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?

Never mind. It’s working now.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists

Agustin said,

August 20, 2008 @ 2:44 am

Your “silly” post (as you called it) helped me out.

I noticed, after a few minutes, “float” alone seemed to be a reserved word, then I remembered the float property should be called with a different name when invoked from javascript.

domObject.cssFloat = value; // That’s the way.

Thanks for your helpful post !

Cordially,
Agustin Garzon

Agustin said,

August 20, 2008 @ 2:48 am

Ohh, by the way, I forgot to mention:

domObject.cssFloat = value; // This will only work on FireFox, will not work in IE.

domObject.styleFloat= value; // This will work on IE but it will not work on FireFox.

lol

Just ensure using both properties together, and that’s it.

Cordially,
Agustin,

RSS feed for comments on this post · TrackBack URI


Leave a Comment