https://api.jquery.com/on/
.on( events [, selector ] [, data ], handler )Returns: jQuery
Description: Attach an event handler function for one or more events to the selected elements.
-
version added: 1.7.on( events [, selector ] [, data ], handler )
-
eventsType: StringOne or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin".
-
selectorType: StringA selector string to filter the descendants of the selected elements that trigger the event. If the selector is
null
or omitted, the event is always triggered when it reaches the selected element. -
dataType: AnythingData to be passed to the handler in
event.data
when an event is triggered. -
handlerA function to execute when the event is triggered. The value
false
is also allowed as a shorthand for a function that simply doesreturn false
.
-
-
version added: 1.7.on( events [, selector ] [, data ] )
-
eventsType: PlainObjectAn object in which the string keys represent one or more space-separated event types and optional namespaces, and the values represent a handler function to be called for the event(s).
-
selectorType: StringA selector string to filter the descendants of the selected elements that will call the handler. If the selector is null or omitted, the handler is always called when it reaches the selected element.
-
dataType: AnythingData to be passed to the handler in
event.data
when an event occurs.
-
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. For help in converting from older jQuery event methods, see .bind()
, .delegate()
, and .live()
. To remove events bound with .on()
, see .off()
. To attach an event that runs only once and then removes itself, see .one()