Skip to content

Instantly share code, notes, and snippets.

@interactiveRob
Last active March 5, 2018 23:05
Show Gist options
  • Save interactiveRob/c4ecedc0a786cc8385f13420342af7f3 to your computer and use it in GitHub Desktop.
Save interactiveRob/c4ecedc0a786cc8385f13420342af7f3 to your computer and use it in GitHub Desktop.
DOM - get list of classes, convert to CSS selector
jQuery(function($){
var classes = [];
$('.page-id-x [class]').each(function(){
$($(this).attr('class').split(' ')).each(function() {
if (this.length>0 && $.inArray(this.valueOf(), classes)==-1) {
classes.push( '.' + this.valueOf() );
}
});
});
console.log("LIST START\n\n"+ classes.join('{}' + '\n')+"\n\nLIST END");
});
@interactiveRob
Copy link
Author

interactiveRob commented Mar 5, 2018

You can use this function to get a list of classes on the page out of the DOM in CSS format. Change .page-id-x on Line 3 to adjust the outermost div that will be checked before moving down the DOM tree.

Then just paste it into the Console and hit Enter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment