On Jun 23, 2005, at 11:30 PM, Focas, Grant wrote:

What about document.getElementById('something').style.display
...
Also, the display property may not yet be set.


The .style object of an element only contains properties that are set within a style attribute in the tag:

<style type="text/css">
span { display:block; }
</style>
...
<span id="foo" style="display:inline;">Foo.</span>
<span id="bar">Bar.</span>
...
<script type="text/javascript">
alert(document.getElementById('foo').style.display); // alerts "inline"
alert(document.getElementById('bar').style.display); // alerts "" or barfs
</script>

The proper DOM method is:

        document.defaultView.getComputedStyle(el,'').getPropertyValue(prop);

...where "el" is the element reference, and "prop" is a hyphenated string representing the CSS property you wish to retrieve (i.e., "background-color" and not "backgroundColor").

IE 5.x (6 too?) doesn't recognize this, but does give you access to the .currentStyle object -- gives you teh same thing but you need to camel-case the property string:

        el.currentStyle.backgroundColor

--

        Ben Curtis : webwright
        bivia : a personal web studio
        http://www.bivia.com
        v: (818) 507-6613



******************************************************
The discussion list for  http://webstandardsgroup.org/

See http://webstandardsgroup.org/mail/guidelines.cfm
for some hints on posting to the list & getting help
******************************************************

Reply via email to