jQuery on() Method
jQuery on() Method
The on() method is used to attach one or more event handlers for the selected elements and child elements. It is relatively new compared to its previous similar functions like bind(), delegate(), etc. For removing these event handlers, we have to use the off() method.
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. |