on() method in jQuery
on() Method
The on() method is used to attach an event to the selected element. The on() method is useful for binding the same handler function to multiple events. You can provide multiple event names separated by spaces as the first argument. In the example below, we add two events click and dblclick on the same element by just separating it with space.
Syntax:-
Its syntax is:- $(selector).on(event,childSelector,data,function,map)
Further Explanation:-
Parameter | Description |
---|---|
event | Required. Specifies one or more event(s) or namespaces to attach to the selected elements. |
childSelector | Optional. Specifies that the event handler should only be attached to the specified child elements. |
data | Optional. Specifies additional data to pass along to the function |
function | Required. Specifies the function to run when the event occurs |
map | Specifies an event map containing one or more events to attach to the selected elements. |