Web Analytics Made Easy -
StatCounter Why does alert(div.style.property) show up blank? - CodingForum

Announcement

Collapse
No announcement yet.

Why does alert(div.style.property) show up blank?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why does alert(div.style.property) show up blank?

    I'm trying to figure out why properties of the style object are sometimes not set! Let's say I have a div with the id "box":

    <div id="box"></div>

    And a css declaration like this:

    div#box
    {
    position: absolute;
    left: 20px;
    }

    Now a Javascript alert:

    alert(document.getElementById("box").style.left);

    It shows up blank! Why is this???

  • #2
    becuse u newer set it before somehow. It shows only after u set it.

    check if there exists div.offsetLeft or something like this

    there are sure offsetHeight and offsetWidth which allways returns measure in px.
    Last edited by BubikolRamios; Oct 3, 2006, 11:46 PM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

    Comment


    • #3
      The style will only alert if its set using style="left:20px;" inside of the div. To get the actual CSS property from the stylesheet you need to use a different method. Read this: http://www.javascriptkit.com/dhtmltu...cascade4.shtml
      ||||If you are getting paid to do a job, don't ask for help on it!||||

      Comment


      • #4
        Thanks for the link!

        It works great!

        Comment

        Working...
        X