Created
October 10, 2013 08:51
-
-
Save larswittenberg/6915197 to your computer and use it in GitHub Desktop.
selector count in css
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
// http://stackoverflow.com/questions/5228459/selector-count-in-css | |
// The following snippet can be run in the Firebug console in Firefox to count | |
// the total number of CSS selectors (not just CSS rules) and check whether | |
// it reaches the limit of 4095 selectors per stylesheet: | |
var | |
styleSheets = document.styleSheets, | |
totalStyleSheets = styleSheets.length; | |
for (var j = 0; j < totalStyleSheets; j++){ | |
var | |
styleSheet = styleSheets[j], | |
rules = styleSheet.cssRules, | |
totalRulesInStylesheet = rules.length, | |
totalSelectorsInStylesheet = 0; | |
for (var i = 0; i < totalRulesInStylesheet; i++) { | |
if (rules[i].selectorText){ | |
totalSelectorsInStylesheet += rules[i].selectorText.split(',').length; | |
} | |
} | |
console.log("Stylesheet: "+styleSheet.href); | |
console.log("Total rules: "+totalRulesInStylesheet); | |
console.log("Total selectors: "+totalSelectorsInStylesheet); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment