The delegate() Method in jQuery is used to add one or more event handlers to the specified element that are children of selected elements and are also used to specify a function to run whenever the event occurs.
$(selector).delegate( childSelector, event, data, function )
Parameter: This method accepts four parameters as mentioned above and described below:
- childSelector: It is required parameter and used to specify one or more child elements attached to the event handler.
- event: It is required parameter and used to specify one or more events attached to the elements. Multiple event values are separated by space and it must be a valid event.
- data: It is an optional parameter and used to specify the additional data to pass along the function.
- function: It is required parameter and used to specify the function to run when the event occurs.
Before Click on the element:
After Click on the element:
Before Click on the button:
After Click on the button:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.