Javascript examples for jQuery Method and Property:bind
The bind() method was deprecated in version 3.0. Use the on() method instead.
The bind() method attaches one or more event handlers for selected elements.
$(selector).bind(event,data,function,map);
Parameter | Require | Description |
---|---|---|
event | Required. | one or more events to attach to the elements. |
data | Optional. | additional data to pass along to the function |
function | Required. | the function to run when the event occurs |
map | Optional. | event map ({event:function, event:function, ...}) to attach to the elements |
The following code shows how to Attach a click event to the <p> element:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").bind("click", function(){ console.log("The paragraph was clicked."); });//from w w w . j a v a 2 s .c om }); </script> </head> <body> <p>Click me!</p> </body> </html>