Question

I have a DOM element that in Firebug clearly shows a float: left property. But when I process it in the DOM, element.style.float returns undefined.

Am I just overlooking something on my end (this is what I'm assuming right now) or is there a special way to address float? I would be baffled if there were.

Was it helpful?

OTHER TIPS

element.style.cssFloat (styleFloat in IE) uses a convention of the browsers to assign attributes as property names in the html engine. Sometimes they work, other times not. keywords can't be property names in a script- class, for, float become className, htmlFor, cssFloat or styleFloat.

The dom syntax is: element.style.getPropertyValue('float'), but that will only work for inline style assignments.

To get any stylesheet defined style you must look deeper:

document.defaultView.getComputedStyle(element,'').getPropertyValue('float');

Note- this is for firefox, opera, chrome, safari. IE has its own methods for style look ups.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top