Last active
April 18, 2016 10:44
-
-
Save nekitozzz/37afa52cca78025c6880 to your computer and use it in GitHub Desktop.
Number of style selectors on page
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
var | |
styleSheets = document.styleSheets, | |
totalStyleSheets = styleSheets.length, | |
totalRules = 0; | |
for (var j = 0; j < totalStyleSheets; j++){ | |
var | |
styleSheet = styleSheets[j], | |
rules = styleSheet.cssRules, | |
totalRulesInStylesheet = rules.length, | |
totalSelectorsInStylesheet = 0; | |
totalRules = totalRules + totalRulesInStylesheet; | |
for (var i = 0; i < totalRulesInStylesheet; i++) { | |
if (rules[i].selectorText){ | |
totalSelectorsInStylesheet += rules[i].selectorText.split(',').length; | |
} | |
} | |
} | |
console.log("Total rules: " + totalRules); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IE8 has limitation for number of style selectors per file (4096).