Thursday, September 10, 2009

Changing HTML class attributes using Javascript

If you try to change the HTML class of an object on the fly using javascript, you might find that it works on Firefox but doesn't work with Internet Explorer. In that case, you're probably doing this:
document.getElementById("myObject").class = "newclass";
However, after being ready to bang my head on the desk for two days and doing a binary search on 500+ subversion revisions to find the exact working/non-working combo for IE, I have discovered this. You ought to use
document.getElementById("myObject").className = "newclass";
Heh... the joys of life.

1 comment:

  1. As you have written Changing HTML class attributes using Javascript.I totally agree with you.If we try to change the HTML class of an object on the fly using javascript, we might find that it works on Firefox but doesn't work with Internet Explorer. In that case,we are probably doing this:

    document.getElementById("myObject").class = "newclass";

    I really liked your blog.
    digital signature Adobe Reader

    ReplyDelete