Skip to content

Instantly share code, notes, and snippets.

@viktorkelemen
Created January 5, 2015 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viktorkelemen/7a887d3b076c00fa0652 to your computer and use it in GitHub Desktop.
Save viktorkelemen/7a887d3b076c00fa0652 to your computer and use it in GitHub Desktop.
Get used selectors from inline stylesheets
function getUsedSelectors() {
var allRules = [];
_.each(document.styleSheets, function (sheet) {
var rules;
if (sheet.rules) {
rules = _.map(sheet.rules, function (rule) {
return rule.selectorText;
});
allRules.push.apply(allRules, rules);
}
});
return _.filter(allRules, function (rule) {
return document.querySelector(rule);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment