Skip to content

Instantly share code, notes, and snippets.

@JoshuaJones
Created September 3, 2013 23:43
Show Gist options
  • Save JoshuaJones/6431077 to your computer and use it in GitHub Desktop.
Save JoshuaJones/6431077 to your computer and use it in GitHub Desktop.
Log out the number of rules and selectors in stylesheets loaded
var selectorsCount = function () {
var styleSheets = document.styleSheets,
totalStyleSheets = styleSheets.length;
console.group('Stylesheet Rules/Selector Debug Info');
console.log('----------------------------------');
try {
for (var j = 0; j < totalStyleSheets; j++) {
var styleSheet = styleSheets[j],
rules = styleSheet.cssRules,
totalRules = rules.length,
totalSelectors = 0;
for (var i = 0; i < totalRules; i++) {
if (rules[i].selectorText) {
totalSelectors += rules[i].selectorText.split(',').length;
}
}
console.log('Stylesheet: ' + styleSheet.href);
console.log('Total Rules: ' + totalRules);
console.log('Total Selectors: ' + totalSelectors);
console.log('----------------------------------');
}
} catch(e) {
console.log('Tried to log something stylesheet related, but failed', e);
}
console.groupEnd();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment