Results 1 to 2 of 2

Thread: DOM Properties

  1. #1

    Thread Starter
    Member Mythrandil's Avatar
    Join Date
    Mar 2006
    Posts
    55

    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?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width