I have a parent div , say with id="to-remove"
This div has multiple children divs and each children div also can have in-turn multiple divs and each of them can have href and/or onclick events.
Is there way to remove all these events from inside this parent div using jquery..?
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.
Use the off() method instead. The unbind() method removes event handlers from selected elements. This method can remove all or selected event handlers, or stop specified functions from running when the event occurs. This method can also unbind event handlers using an event object.
The unbind() Method is an inbuilt method in jQuery which is used to remove any selected event handlers. This method can be used to remove particular event handler, or stop specific functions. It works on any event handler using an event object.
jQuery bind() function is used to attach an event handler to elements, while the unbind() is used to detached an existing event handler from elements.
Did you try .unbind()
:
$('#to-remove *').unbind('click'); // just for click events
$('#to-remove *').unbind(); // for all events
And as of jQuery 1.7, the .on()
and .off()
methods are preferred to attach and remove event handlers on elements. (from .unbind()
documentation) So if you're using jQuery > 1.7.x then this would be better:
$('#to-remove *').off();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With