With Internet Explorer, Javascript setAttribute(‘style’, ‘something’) doesn’t work in IE

If you try and set the style attribute of a DOM element with Javascript, the following code WON’T WORK IN IE:

yourelement.setAttribute('style','left:150px; top:150px;');

Instead use:

yourelement.style.cssText = 'left:150px; top:150px;';

Thanks to Rob on this page

http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work_in_IE_when_used_with_th.html

http://blog.throbs.net/

2 thoughts on “With Internet Explorer, Javascript setAttribute(‘style’, ‘something’) doesn’t work in IE”

Leave a Reply

Your email address will not be published. Required fields are marked *