Skip to content

Instantly share code, notes, and snippets.

@pcdinh
Forked from stubbetje/debug.unusedstylesheets.js
Created December 9, 2009 09:04
Show Gist options
  • Save pcdinh/252355 to your computer and use it in GitHub Desktop.
Save pcdinh/252355 to your computer and use it in GitHub Desktop.
// 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