Skip to content

Instantly share code, notes, and snippets.

@najmam
Created December 22, 2022 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save najmam/d208f2e96345307a73144206155248f6 to your computer and use it in GitHub Desktop.
Save najmam/d208f2e96345307a73144206155248f6 to your computer and use it in GitHub Desktop.
Lists all CSS classes referred to in a document. Run this in a web browser console.
(() => { // list all css classes referred to in the document
const classes = new Set();
function findClasses(el) {
if(el.hasAttribute('class')) {
const cls = el.getAttribute('class').split(' ');
for(let cl of cls) {
classes.add(cl);
}
}
for(let child of el.children) {
findClasses(child);
}
}
findClasses(document.querySelector('body'));
const sorted = Array.from(classes.values());
sorted.sort();
console.log(sorted.join("\n"));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment