Skip to content

Instantly share code, notes, and snippets.

@jamesmthornton
Last active July 10, 2020 21:18
Show Gist options
  • Save jamesmthornton/3d53a26cdbe54fa6974f1faaf30acd56 to your computer and use it in GitHub Desktop.
Save jamesmthornton/3d53a26cdbe54fa6974f1faaf30acd56 to your computer and use it in GitHub Desktop.
Remove tags, class attributes and attribute contents from DOM
// 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