Skip to content

Instantly share code, notes, and snippets.

@benfoxall
Created June 25, 2013 11:44
Show Gist options
  • Save benfoxall/5857853 to your computer and use it in GitHub Desktop.
Save benfoxall/5857853 to your computer and use it in GitHub Desktop.
quick function to find which selectors aren't being used.
function each(items,fn){[].forEach.call(items,fn)}
each(document.styleSheets, function(sheet){
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