The undelegate() method is an inbuilt method in jQuery which is used to remove the specified event handler from the selected element.
$(selector).undelegate(selector, event, function)
Parameters: This method accepts three parameters as mentioned above and described below:
- selector: It is an optional parameter which is used to specify the selector from which event will remove.
- event: It is an optional parameter which is used to specify the name of the event type on the selector.
- function: It is an optional parameter which is used to specify the name of the handler function to remove.
Return Value: This method returns the selected element with specified changes made by undelegate() method.
Below examples illustrate the undelegate() method in jQuery:
Example 1: This example does not contain any parameters.
Before click anywhere:
After click on the paragraph:
Note: First click on the button and then click on the paragraph, then no changes occur.
Example 2: This example contains all parameters.
Before clicking anywhere:
After clicking on the div element get resized.
Note: If click on the button and then click on the div element then no change in the size will take place.
This article is attributed to GeeksforGeeks.org