Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all click event handlers using jQuery?

People also ask

How do you remove a click handler?

Now to remove the click event handler from the click event of the button, just use the removeEventListener() event handler as follows: btn. removeEventListener('click', handler); Note that the event name and the event handler function must be the same for removeEventListener() to work.

How do I remove all event listeners?

You can remove all event listeners from a DOM element in Javascript by replacing the element with a deep clone of itself. elem. cloneNode(...) will not clone the event listeners of the source element.

What method is used to remove an event handler?

The removeEventListener() method removes an event handler from an element.

Which jQuery function removes previously attached event handlers on the element?

The . off() method removes event handlers that were attached with .


You would use off() to remove an event like so:

$("#saveBtn").off("click");

but this will remove all click events bound to this element. If the function with SaveQuestion is the only event bound then the above will do it. If not do the following:

$("#saveBtn").off("click").click(function() { saveQuestion(id); });

Is there a way to remove all previous click events that have been assigned to a button?

$('#saveBtn').unbind('click').click(function(){saveQuestion(id)});

$('#saveBtn').off('click').click(function(){saveQuestion(id)});

If you used...

$(function(){
    function myFunc() {
        // ... do something ...
    };
    $('#saveBtn').click(myFunc);
});

... then it will be easier to unbind later.