Skip to content

Instantly share code, notes, and snippets.

@rickcnagy
Created December 23, 2018 20:05
Show Gist options
  • Save rickcnagy/d96fa7d2a6b16df6236268a29a6499c1 to your computer and use it in GitHub Desktop.
Save rickcnagy/d96fa7d2a6b16df6236268a29a6499c1 to your computer and use it in GitHub Desktop.
Logs all the unused style rules in loaded stylesheets.
function logUnusedStyleRules() {
const unusedRules = [];
[...document.styleSheets].forEach((sheet) => {
[...sheet.rules].forEach((rule) => {
if (!document.querySelector(rule.selectorText)) {
unusedRules.push(rule);
}
});
});
console.log(unusedRules);
}
logUnusedStyleRules();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment