Skip to content

Instantly share code, notes, and snippets.

@wayspurrchen
Last active August 29, 2015 14:13
Show Gist options
  • Save wayspurrchen/c688b2d9685418901791 to your computer and use it in GitHub Desktop.
Save wayspurrchen/c688b2d9685418901791 to your computer and use it in GitHub Desktop.
Grab and list all (unique) classes on page
var cls = [];
Array.prototype.slice.call( document.querySelectorAll('*'), 0 ).forEach( function ( el ) {
cls = cls.concat( Array.prototype.slice.call( el.classList, 0 ) );
} );
cls = cls.reduce( function ( p, c ) {
if ( p.indexOf( c ) < 0 ) p.push( c );
return p;
}, [] );
console.log( cls );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment