Created
January 5, 2015 12:27
-
-
Save viktorkelemen/7a887d3b076c00fa0652 to your computer and use it in GitHub Desktop.
Get used selectors from inline stylesheets
This file contains hidden or 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
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