Posted by Seree.
Posted by Seree.
Use JavaScript to change “float” style
Hey friends,
In a few days ago, I’ve just stuck with how to change “float” style in JavaScript and very confuse why it doesn’t work at all!
I’m using …
var obj = document.getElementById(“some1”);
obj.style.float = “left”;
No luck at all. I tried both on Internet Explorer and Firefox. Even I use Internet Explorer Toolbar and Firebug. I can change the style via that tools but no luck with JavaScript.
Silly?
I’m fool with DOM. I try to find a solution and suddenly found that.
In DOM, there are no “float” property but “cssFloat”.
Just change my code to …
var obj = document.getElementById(“some1”);
obj.style.cssFloat = “left”;
Really silly huh?
Ohh thx!
i figured that it needed something in front, since float really is a datatype, so using it in obj.style.float would be impossible.
Bless you for posting this! I was tearing my hair out trying to figure out why my float code worked in FF but not IE!! And styleFloat works like a dream.
Thanks man, very helpful! Much appreciated
Here is a little workaround for this problem:
obj.setAttribute(“style”, obj.getAttribute(“style”) + “; float:left; “);
The leading semicolon must be set because the IE sometimes changes the styles and always misses out the last semicolon.
float is a reserved word in about every programming language, so it’s not silly.
Thanks a lot.. very help ful to me..
So that makes him plain stupid.
« How do you do when dealing with cross-browser web development? Next Post
Why my .style.left doesn”t work with FireFox? »
Under IE6 you must use this:
obj.style.styleFloat=’left’;