Posted By

Todd on 03/20/07


class ie cross-browser className

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


class and className

 / Published in: JavaScript


One notorious discrepancy between IE and Firefox (or other "good" browsers) is the way they access the class HTML attribute. While I've used more complicated solutions in the past, this simple solution doesn't require any browser detection or even a function to set the class attribute that is used. Click the URL above for an explanation of how it works (see the comment by "penders").

  1. object.className
  3. /* Example: */
  4. var someObjectsClass = this.className;

Report this snippet  

You need to login to post a comment.