setAttribute does not work in IE
Life ain’t so smooth for coders often. Often times developing websites making them cross-browser compatible makes life a nightmare.
Try this code:
document.getElementById(“myElementId”).setAttribute(“class”, “myclass”);
This code works fine in Mozilla and many other major browsers. But hey once again our friend Internet Explorer doesn’t work with it.
There are several solutions to work with this. You can assign individual style elements seperately. For example:
document.getElementById(“myElementId”).style.color=’#000′;
However problem is not over yet. You cant assign all the style attributes. For example if you want make a text italic, this assignment wont work in Google Chrome.
document.getElementById(“myElementId”).style.fontStyle=’italic’;
Cross Browser Solution?
This solution seem to work on IE 7, IE 8, Mozilla, Chrome, Safari.
document.getElementById(“myElementId”).className=’searchBox2′;










thank you! this solves everything was trying to figure this out for an hour.
Leave your response!