Skip to content

Instantly share code, notes, and snippets.

@bmvakili
Last active May 22, 2017 02:21
Show Gist options
  • Save bmvakili/8c390edaa5ee0db4040f2a57abc68748 to your computer and use it in GitHub Desktop.
Save bmvakili/8c390edaa5ee0db4040f2a57abc68748 to your computer and use it in GitHub Desktop.
List all selectors across DOM stylesheets
function logSortedCSSSelectorsOnStylesheets(stylesheets) {
var ruleset = new Set();
for (var stylesheet in stylesheets) {
var rules = stylesheets[stylesheet].rules;
for (var rule in rules) {
var stylesheetRule = rules[rule];
if (stylesheetRule.selectorText) {
ruleset.add(stylesheetRule.selectorText);
}
}
}
ruleset = Array.from(ruleset).sort();
for (var rule in ruleset) {
console.log(ruleset[rule]);
}
}
var stylesheets = document.styleSheets;
logSortedCSSSelectorsOnStylesheets(stylesheets);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment