Javascript examples for jQuery Method and Property:on
The on() method attaches one or more event handlers for the selected elements and future added child elements.
Parameter | Require | Description |
---|---|---|
event | Required. | one or more event(s) or namespaces to attach to the selected elements. |
childSelector | Optional. | the event handler should only be attached to the specified child elements |
data | Optional. | additional data to pass along to the function |
function | Required. | the function to run when the event occurs |
map | Optional. | an event map ({event:function, event:function, ...}) to attach to the selected elements to run when the events occur |
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").on("click dblclick", function(){ $(this).animate({fontSize: "+=6px"}); });//www .j a va2 s.c o m }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <p>Click and double click any p element to increase its text size.</p> </body> </html>