Wednesday, August 26, 2009

Use className instead of class for IE.


In my many previous posts, I have explained about using setAttribute method for dynamically creating Webpages.

But we faced some issues when we tried to use setAttribute for dynamically changing the CSS style class name for a div tag.

i-e We tried to use below code for setting "current" as CSS style class for a div tag with id "desc"

document.getElementById('desc').setAttribute('class','current');


The above code worked in FireFox. But it didn't work in IE (Internet Explorer).

We came to know that we should use ‘className’ instead of 'class' in IE.

So, in IE, the code should look as below,

document.getElementById('desc').setAttribute('className','current');


We have to use javascript code for using the required code based on user's browser.


More Articles...

No comments:

Search This Blog