SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question getting position of an element... stumped

    I'm puzzled by how this works (or doesn't so far...)

    I'm playing with Kevin Yank's code for a popup menu. What I need is to make the popup relative to the position of the menu button, which is in a centered table.

    So, I was thinking if I can read the position of the menu button on the page, then I can set the popup menu to the proper location. The problem is that I can't seem to get that position.

    In the course of testing, I tried this code to set and then read the position of one of the popup menus:

    menu4.style.left = 680;
    alert(menu4.style.left);


    This works fine, it sets the left position of the menu, and can read the position back to me as a test.

    But when I try just reading the menu position without previously setting it, as in:

    alert(menu4.style.left);

    it comes back with a null string. However the menu exists and has a left position... I can see it pop up!

    Why is this happening?

    john

  2. #2
    SitePoint Evangelist azizur_rahman's Avatar
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    menu4.style.left = 680;
    alert(menu4.style.left);

    is different from
    alert(menu4.style.left);

    The menu4.style.left = 680; sets the value and next one reads it.... its easy as saying store x=680 next saying tell me what is the value of x.

    but alert(menu4.style.left); you are trying to read the value is not reference to a complete DOM or does not exist within the DOM. if you look at you code for menu4 does is have thefollowing attrivutes set? name=menu4 or id=menu4 ?


    have you tried:
    alert(document.menu4.style.left);

    some of this may not work on Netscape or other browsers...
    Azizur Rahman
    Web Application Developer


Bookmarks

Posting Permissions

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