jQuery Event Handler

Last Updated Jul 21, 2015, 12:00:06 PM





jQuery delegate() Method

jQuery delegate() method is used to attach a handler to one or more events for all matched elements.

Syntax

As of jQuery 1.7, delegate() method has been substituted by the .on() method. Earlier version the most effective way to use the event was delegation.

Here is an example to use jquery delegate() method

Example

In the above example, what jquery delegate() method does is , everytime you click on the html body content, it will add another paragraph which contains text "Added another element"

Output


Try It Now

jQuery on() Method

jQuery on() event method is used to attach one or more handler to the matched elements in the DOM tree.

Syntax

jQuery on() method attaches event handlers to the set of selected elements in the jQuery object. As of jQuery 1.7, the jquery on() method provides all functionality required for attaching event handlers.

Example

The above example jquery on() method , everytime you click on the body element it will add another paragraph element with count

Output


Try It Now

Other Advanced jQuery Events you might want to learn

jQuery Complete Events Reference

jQuery Events

jQuery Document Events

jQuery Keyboard Events

jQuery Mouse Events



Sources and Credits

The content and methods in the tutorial has been referred and updated with jQuery API and The jQuery Foundation

Last Updated Jul 21, 2015, 12:00:06 PM