Thursday 12 April 2012

Javascript IE/Firefox Float Issue and Solution

When trying to set the 'float' style using Javascript you may have seen that in IE 8 and below it doesn't work.


The common approach people will try is:


div.style.float = "left";


IE 8 and below does not support this so here is the solution:


You need to use either "cssFloat" or "styleFloat" for IE but you need "cssFloat" for Firefox.


I place both as the example below.


Example:


div.style.styleFloat="left";
div.style.cssFloat="left";