Skip to main content

With jQuery it is easy to add events to our HTML elements.

<div id="buttondiv">Button</div>

In this example method bind() will be used. It attaches the specific event to the given element.

- Advertisement -
- Advertisement -

bind(eventType, data, handler)

  • eventType — A string that specifies the type of the event
  • data — The data that is passed to the event handler for processing
  • handler — The function that contains the statements to perform on occurrence of the given event.

So, for this purpose we'll attach click event to the button div:

$(document).ready(function() {
    $('#buttondiv').bind('click', function(){
        alert('Button is clicked.');

To unbind any event previously attached to an element use unbind() function:


- Advertisement -