Home > Web > Tips’n’tricks: CSS float in JavaScript

Tips’n’tricks: CSS float in JavaScript


The CSS float property it is often used (if you don’t layout your pages with evil pages). It is pretty easy to setup using CSS code:

float: left;

.

If you want to setup a CSS property from JavaScript it is usually done using the syntax:

element.style.property = value;

and - signs are replaced with camel case (e.g. backgroundColor instead of background-color).
This won’t work for float too. float is a reserved JavaScript word, so you should use cssFloat instead. As usual😉, Internet Explorer is special and you should use styleFloat instead.

That’s it. Short small tip, but very useful if you want to dynamically modify the flow of elements.

Categories: Web Tags: , ,
  1. August 17, 2008 at 9:21 pm

    This is the same with property className which refers to the class attribute (as class it is a reserved JavaScript word)

  2. Alexwebmaster
    March 3, 2009 at 12:14 pm

    Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: