Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a cross browser way of setting style.float in Javascript?

Tags:

Usually, if you need to set a style attribute in JavaScript, you say something like:

element.style.attribute = "value"; 

There are slight variations but usually the attribute name is a similar, albeit camelcased, version of the HTML attribute name.

The problem for me is that the float attribute doesn't work. Float is a keyword in JavaScript and so style.float makes all the JavaScript for the page break. I looked in MSDN, and it said to use styleFloat like so:

element.style.styleFloat = "value"; 

That only works in IE. Firefox, Safari, Chrome, Opera - none of them seem to have an answer. Where am I going wrong? There has to be a simple answer to this.

like image 794
Larden Hughes Avatar asked Mar 03 '09 13:03

Larden Hughes


People also ask

How does a JavaScript method helps of enabling cross-browser Mcq?

JavaScript # JavaScript is the most common method of enabling cross-browser CSS3 features support, and it can either be used as a substitute for or to enable CSS3 properties in older browsers or be used as an alternative.

How do I display a specific HTML browser?

Open the Google Chrome page of the specific HTML that you want to inspect. Press "Control" + "U" on the keyboard and a separate page with the source code appears. This allows you to view the HTML in a separate browser, allowing you to compare it to the webpage.


1 Answers

Use cssFloat as in...

element.style.cssFloat = "value"; 

That works in everything except IE 8 and older, but you can always detect the browser and switch, or just set them both. Unfortuantely, there is no way to set just one style value to work in all browsers.

So to summarize, everyone you need to set the float, just say:

element.style.styleFloat = "value"; element.style.cssFloat = "value"; 

That should work everywhere.

like image 128
3 revs, 2 users 74%lfonlfonlfon Avatar answered Sep 27 '22 21:09

3 revs, 2 users 74%lfonlfonlfon