Now this is an ancient question, but, given that all major browsers have abandoned EventTarget.getEventListeners() , there is a way to remove ALL event handlers for the element and its children and preserve only the HTML structure. We simply clone the element and replace it:
let e = document.querySelector('selector'); let clone = e.cloneNode(true); e.replaceWith(clone);
This is the same hack as addEventListener() method with a method that tracks each handler function, but at least it can be used after the DOM is already connected to other script events.
This also works in much the same way as above, using jQuery clone() instead of cloneNode() :
let original = $('#my-div'); let clone = original.clone(); original.replaceWith(clone);
This template will not actually leave event handlers on the element or its child nodes, unless they are defined using the attribute like onclick="foo()" .
Akash Dec 12 '17 at 7:27 2017-12-12 07:27
source share