Posted By

Todd on 03/20/07


Tagged

class ie cross-browser className


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

basicmagic
vali29


class and className


 / Published in: JavaScript
 

URL: http://www.webmasterworld.com/javascript/3090396.htm

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
  2.  
  3. /* Example: */
  4. var someObjectsClass = this.className;

Report this snippet  

You need to login to post a comment.