The delegate () method adds one or more event handlers for the specified element (which is a child of the selected element) and specifies the function to run when these events occur
delegate 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.
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. |
Grammar
$ (selector). Delegate (Childselector,event,data,function)
Return value: JQuery delegate (SELECTOR,[TYPE],[DATA],FN)
Overview
The specified element (child elements that belong to the selected elementAdds one or more event handlers, and specifies the function to run when these events occur.
Parameters
Selector,[type],fnstring,string,function V1.4.2
Selector: selector string for the element that the filter triggers the event.
Type: One or more events attached to the element. Multiple event values are separated by a space. Must be a valid event.
fn: A function that runs when an event occurs 
Selector,[type],[data],fnstring,string,object,function V1.4.2< Span class= "Apple-converted-space" >&NBSP;
Selector: selector string for the element that the filter triggers the event. &NBSP;
Type: One or more events attached to the element. Multiple event values are separated by a space. Must be a valid event. ,
Data: Additional data passed to the function &NBSP;
fn: Functions that run when an event occurs &NBSP;
selector,eventsstring,string v1.4.3&NBSP;
Selector: selector string for the element that the filter triggers the event. &NBSP;
Events: A data map of one or more event type strings and functions to execute them. &NBSP;
Example :&NBSP;
hides or displays the P element when the mouse is clicked: &NBSP;
HTML Code: Span class= "Apple-converted-space" >&NBSP;
< div > < p > this is a paragraph. </ p > < button > click here </ button > </ div >
JQuery code: &NBSP;
$ ("div"). Delegate ("button", "click", function () {$ ("P"). Slidetoggle (); });
Description: Delegate This method can be used as an alternative to the live () method, allowing each event to be bound to a specific DOM element. &NBSP;
The following two-segment code is equivalent: &NBSP;
function () {$ (this). Toggleclass ("hover"); }); $ ("table"). each (thefunctionthisfunction() {$(this). Toggleclass ("hover");});
Introduction to delegate () usage in jquery