Skip to content

Instantly share code, notes, and snippets.

@jgable
Created September 11, 2013 18:12
Show Gist options
  • Save jgable/6527516 to your computer and use it in GitHub Desktop.
Save jgable/6527516 to your computer and use it in GitHub Desktop.
Stylesheet Selector
var styleSheets = document.styleSheets,
totalRules = 0;
styleSheets = Array.prototype.slice.call(styleSheets, 0);
styleSheets.forEach(function (stylesheet) {
if (!stylesheet.cssRules) {
return;
}
var rules = Array.prototype.slice.call(stylesheet.cssRules, 0),
rulesInSheet = rules.length,
selectorsInSheet = 0;
rules.forEach(function (rule) {
if (rule.selectorText) {
selectorsInSheet += rule.selectorText.split(',').length;
}
});
console.group();
console.log("Stylesheet:", stylesheet.href);
console.log(" Rules:", rulesInSheet);
console.log("Selectors:", selectorsInSheet);
console.groupEnd();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment