Last active
July 10, 2020 21:18
-
-
Save jamesmthornton/3d53a26cdbe54fa6974f1faaf30acd56 to your computer and use it in GitHub Desktop.
Remove tags, class attributes and attribute contents from DOM
This file contains 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
// Remove all class attributes and contents from divs in the DOM | |
var myDivs = document.getElementsByTagName('div'); // replace div with span for spans | |
for (var i = 0; i < myDivs.length; i++) { | |
myDivs[i].removeAttribute('class'); // replace class with any attribute you want stripped out | |
} | |
// Remove all SVGs from the DOM | |
var collectSvg = document.getElementsByTagName('svg'); | |
for (var i = 0; i < collectSvg.length; i++) { | |
collectSvg[i].parentNode.removeChild(collectSvg[i]); | |
console.log( (i) ); // with count | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment