Skip to content

Instantly share code, notes, and snippets.

@CrocoDillon
Last active December 28, 2015 00:29
Show Gist options
  • Save CrocoDillon/7413919 to your computer and use it in GitHub Desktop.
Save CrocoDillon/7413919 to your computer and use it in GitHub Desktop.
Get all class names of a document. Useful for... whatever.
var classes = [];
Array.prototype.forEach.call(document.querySelectorAll('*'), function(el) {
el.className.split(/\s/).forEach(function(cl) {
if (cl && classes.indexOf(cl) == -1)
classes.push(cl);
});
});
classes.sort();
classes.forEach(function(cl) {
console.log(cl);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment