Skip to content

Instantly share code, notes, and snippets.

@nelix
Forked from benfoxall/unusedcss.js
Created July 17, 2013 06:54
Show Gist options
  • Save nelix/6018220 to your computer and use it in GitHub Desktop.
Save nelix/6018220 to your computer and use it in GitHub Desktop.
function each(items,fn){[].forEach.call(items,fn)}
each(document.styleSheets, function(sheet){
if (sheet.cssRules) each(sheet.cssRules, function(r){
try{
// look for the first matching element
if(!document.querySelectorAll(r.selectorText)[0])
console.log("Unused Selector: ", r.selectorText);
} catch (e){
console.log('unable to process', r.selectorText, e)
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment