Ivan Porto Carrero

IO(thoughts) flatMap (_.propagandize)

18

Oct
2007

Get All the Css Classes in Use on Your Page

By using javascript that can be done pretty easily. The script below requires prototype

var classes = [];
function collectClasses(ele){
  var children = ele.childElements();
  if(children.length > 0){
    children.each(function(el){collectClasses(el);});
  }
  else{
   ele.classNames()
     .each(function(className){classes.push(className)});
   return classes;
  }
}
var body = document.getElementsByTagName(‘body’)[0];
collectClasses(body);
var myUniqueClasses = classes.uniq();

 

The myUniqueClasses variable holds all the classnames that are in use on your page.

 

 

del.icio.us tags: javascript, dhtml

To top