Last active
March 5, 2018 23:05
-
-
Save interactiveRob/c4ecedc0a786cc8385f13420342af7f3 to your computer and use it in GitHub Desktop.
DOM - get list of classes, convert to CSS selector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.