Created
May 29, 2024 12:13
-
-
Save archy-bold/ad2150874d6fb422ea5f3362c229adc2 to your computer and use it in GitHub Desktop.
Remove all event listeners from element in JavaScript, retain listeners on child elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Working for document.body | |
var nodes = []; | |
document.body.childNodes.forEach((node) => nodes.push(node)); | |
document.body.innerHTML = ""; | |
document.body.outerHTML = document.body.outerHTML; | |
nodes.forEach((node) => document.body.appendChild(node)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment