-
DOM Properties
When i query an objects properties they are blank
for example:
var node = document.getElementById("id")
var sdisplay = node.style.display
sdisplay will be blank, however the object has been assigned a display setting (blank, and the object does abide by the setting).
I can assign to the property and from then onwards i can retrieve it etc its just when the page initially loads.
Any ideas?
-
Re: DOM Properties
The style property represents the inline styles of the element, not the active styles. If the display property was set via a CSS rule, it won't show up.
Due to lack of support in IE, there is no portable way of retrieving the active style of an element. The standard (DOM 2 Style Module, chapter CSS) method is using the getComputedStyle() method of the window (or any other ViewCSS) object. You pass it the node and the pseudo-element, and it will return the currently active fully computed style.
In IE, you can instead use the currentStyle property of the node object itself. This method doesn't allow retrieving the style of pseudo-elements, but then, IE doesn't support them anyway.
See also this article for more information:
http://www.oreillynet.com/pub/a/java...p5/index5.html
Be aware of at least one mistake, though: there is no need to call the getPropertyValue() method on the return value of getComputedStyle(). You can use array indexing syntax and use the JS-style property names that you're used to.