jquery on method can be used to bind events on dom elements. It also supports event delegation.
jQuery
.on()
attach an event handler function for one or more events to the selected elements. docs
$("selector").on( events [, selector ] [, data ], handler )
The .on()
method attaches event handlers to the currently selected set of elements in the jQuery object. As of jQuery 1.7, the .on()
method provides all functionality required for attaching event handlers.
Examples
// Example 1
$("div").on("click", function(){
// do something
});
// Example 2
function notify() {
// do something
}
$("button").on("click", notify);
// Example 3
$("input").on("keyup keydown", function(){
// do something
});