How to remove all event listeners from a DOM element in Javascript

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.

remove_event_listeners_demo.js
elem.replaceWith(elem.cloneNode(true));

Full example:

remove_event_listeners_full_example.js
var elem = document.getElementById('mybutton');
elem.replaceWith(elem.cloneNode(true));

Source for the original (partial) suggestion on StackOverflow: @Felix Kling


Check out similar posts by category: Javascript