Last active
May 22, 2017 02:21
-
-
Save bmvakili/8c390edaa5ee0db4040f2a57abc68748 to your computer and use it in GitHub Desktop.
List all selectors across DOM stylesheets
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
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