Skip to content

Instantly share code, notes, and snippets.

@stubbetje
Created February 16, 2009 16:01
Show Gist options
  • Save stubbetje/65227 to your computer and use it in GitHub Desktop.
Save stubbetje/65227 to your computer and use it in GitHub Desktop.
create list of unused stylesheet rules
// create list of unused stylesheet rules
$(document).ready(function()
{
var sel = [];
for( var s = 0 ; s < document.styleSheets.length ; s++ ) {
var rules = document.styleSheets[s].cssRules || document.styleSheets[s].rules;
for( var r = 0 ; r < rules.length ; r++ ) {
if( rules[r].selectorText ) {
var pieces = rules[r].selectorText.split(',');
for( var p = 0 ; p < pieces.length ; p++ ) {
var selectorText = pieces[p].toLowerCase();
try {
if( $( selectorText ).size() == 0 ) {
sel.push( $.trim(selectorText) );
}
} catch( e ) {
console.log( selectorText );
}
}
}
}
}
$(document.body).prepend( '<div class="std-msg-info"><em>Unused stylesheet rules:</em><pre>' + sel.join('\n') + '</pre></div>' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment