Definition and usage
The delegate () method adds one or more event handlers for the specified element (the child element of the selected element) and specifies the function to run when these events occur.
Event handlers that use the delegate () method apply to current or future elements, such as new elements created by a script.
Grammar
$ (selector). Delegate (Childselector,event,data,function)
Parameters |
Description |
Childselector |
Necessary. Specifies one or more child elements to attach the event handler. |
Event |
Necessary. Specifies one or more events that are attached to an element. Multiple event values are separated by a space. Must be a valid event. |
Data |
Optional. Specifies additional data that is passed to the function. |
function |
Necessary. Specifies the function to run when an event occurs. |
undelegate () methodInstance
Removes all event handlers added by the delegate () method from all elements:
$ ("Body"). Undelegate ();
Definition and usage
The Undelegate () method deletes one or more event handlers that were added by the delegate () method.
Grammar
$ (selector). Undelegate (selector,event,function)
Parameters |
Description |
Selector |
Optional. Specifies the selector that needs to delete the event handler. |
Event |
Optional. Specifies one or more event types for which the handler function needs to be deleted. |
function |
Optional. Specifies the specific event handler to delete. |
Try it yourself-example
-
Delete event handlers, added by delegate (), from a specific selector
-
How to use the Undelegate () method to remove all event handlers from the specified element.
-
Deletes an event handler for the specified event type, added by delegate (), from the specified element
-
How to use the Undelegate () method to remove all event handlers for a specific event type from the specified element.
-
Delete the specific function added by delegate ()
-
How to use the Undelegate () method to remove specific functions from a specific event type for an event handler.
JQuery (i) delegate () method