Here, the task is to remove an event handler in the jQuery/JavaScript. There are three methods to solve this problem which are discussed below:
Using unbind() method: It is an inbuilt method in jQuery which is used to remove any selected event handlers.
Syntax:
$(selector).unbind(event, function, eventObj)
Approach:
- Select the selector on which the event handler is to be removed.
- Use the unbind() method to remove event.
- After click on the function under which unbind works will remove the event handler.
Example 1:
<!DOCTYPE html> <html> <head> <title> jQuery | How to remove an event handler? </title> </head> <body style = "text-align:center;"> <h1 style = "color:green;" > GeeksForGeeks </h1> <h3> Remove an event handler using unbind method </h3> <h4>Element to remove</h4> <button> Click Here </button> <script> $(document).ready(function() { $("h4").click(function() { $(this).slideToggle(); }); $("button").click(function() { $("h4").unbind(); }); }); </script> </body> </html> |
Output:
- Before click anywhere:

- After click on the element h4:

- After clicking on the button event will not work:

Using off() Method: It is used to remove event handlers attached with the on() method.
Syntax:
$(selector).off(event, selector, function(eventObj), map)
Approach:
- Select the selector on which the event handler is to be removed.
- Use the off() method to remove event.
- After click on the function under which unbind works will remove the event handler.
Example 2:
<!DOCTYPE html> <html> <head> <title> jQuery | How to remove an event handler? </title> </head> <body style = "text-align:center;"> <h1 style = "color:green;" > GeeksForGeeks </h1> <h3> Remove an event handler using off method </h3> <h4>Element to remove</h4> <button> Click Here </button> <script> $(document).ready(function() { $("h4").click(function() { $(this).slideToggle(); }); $("button").click(function() { $("h4").off(); }); }); </script> </body> </html> |
Outout:
- Before click anywhere:

- After click on the element h4:

- After clicking on the button event will not work:

Recommended Posts:
- How to unbind “hover” event using JQuery?
- jQuery | event.currentTarget Property
- jQuery | event.data Property
- jQuery | event.stopPropagation() Method
- jQuery | event.isPropagationStopped() Method
- jQuery | event.namespace Property
- jQuery | event.isImmediatePropagationStopped() Method
- jQuery lose focus event
- jQuery | event.stopImmediatePropagation() Method
- jQuery | Selectors and Event Methods
- jQuery | event.timeStamp property with Example
- jQuery | event.relatedTarget Property with Example
- jQuery event.metaKey Property
- jQuery | event.isDefaultPrevented() Method
- jQuery | event.target Property with Example
- jQuery | event.delegateTarget Property
- jQuery | Autocomplete Selection Event
- jQuery | event.which property with Examples
- jQuery | event.preventDefault() Method
- How to determine the direction of a jQuery scroll event?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

