Did you find this useful?
Socialize it today.


jQuery Bind Event

Wednesday, June 13, 2012

The jQuery event bind() method attaches one or more event handlers for selected elements, and specifies a function to run when the events occur. As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document. For earlier versions, the .bind() method is used for attaching an event handler directly to elements.


Syntax

$(selector).bind(event(s),data,function)


ParameterDescription
eventOne or more events to attach. Multiple values are separated by space.
dataOptional data to pass along to the function
functionFunction to run when the event(s) occur


Example


$("#close").bind("click",function () {
    $("#div1").slideUp(500);
     });


In the jQuery code listed above, the bind() method attaches the click event and specifies that the "slideUp" method to run on the element with an id of #div1. The result of the code is as follows.


Click on the icon to the right to hide me!
close

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

Pro jQuery HTML CSS and JavaScript Editor JavaScript and jQuery: The Missing Manual