setting css float with javascript in IE

September 29th, 2006 by Coos

Just a quick reminder to self:
IE 6 (7) don’t seem to render style.float when set with javascript,
so when you want a div to float left *dont* try using:

 div.styleFloat = 'left';
 div.style['float'] = ‘left’;
 div.style.float = ‘left’;


but create a class:

 .fll { float:left; }
 .flr { float:right; }
 .fln { float:none; }

and set the classname in javascript to invoke float:

 div.className="fll";

Another issue with IE and IE only is that setting your style directives with:

 div.setAttribute("style", "float:left;" );

doesn’t seem to work: setting background-image, font-size, floats or any other css style item will not render. damn.

Comments are closed.