#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    4
    Rep Power
    0

    Unhappy Problem accessing DIV tag properties from javascript


    Hi,
    This is the code I have on the page:

    <BODY>
    <div id="prognav" style="position:absolute; left:34%; top:145px; width:460px; height:53px; z-index:1; visibility:hidden">
    ------------Some stuff-----------------
    </div>
    </BODY>

    I need to access the left and top attributes in order to reset these values when the window is resized. I tried these bits of code, but it kept giving me errors in Netscape.

    if(document.layers)
    alert(document.layers["prognav"].left);
    ERROR: document.layers has no properties

    also tried this:
    if(document.layers)
    alert(document.prognav.left);
    ERROR: document.prognav has no properties

    How else am I supposed to access this. Thanks in advance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    New York
    Posts
    122
    Rep Power
    14
    Based on your other thread, I assume you're experiencing problems in Netscape6.1. Is this correct?

    For Netscape6.1, the following should work in theory:

    if (document.all) {
    // IE code
    } else if (document.layers) {
    // NN4.x code
    } else if (document.getElementById) {
    var x_pos = document.getElementByid("prognav").style.left;
    alert(x_pos);
    }


    However, I was experiencing a problem with code similar to this last night. "style.left" did not seem to have a readable value until I had manually set it with Javascript rather than css.

    So I had to do the following:

    } else if (document.getElementById) {
    document.getElementByid("prognav").style.left = "100px" // or some other string value
    var x_pos = document.getElementByid("prognav").style.left;
    alert(x_pos);
    }



    Also, if I were you, I would avoid using a percentage-value for you left attribute in the css declaration. The results will probably erratic across browsers.

    Good luck.

IMN logo majestic logo threadwatch logo seochat tools logo