Absolute position?

Discussion in 'Javascript' started by Samuel, Nov 8, 2006.

  1. Samuel

    Samuel Guest

    Hi,

    Is it possible to get absolute position of element with javascript?
    e.g. I have textbox somewhere in table. Textbox relative to table cell
    position is 0,0. How can I get Textbox absolute position on page??
    Please, any ideas, I'm going crazy...

    thanks
    Samuel, Nov 8, 2006
    #1
    1. Advertising

  2. Samuel

    Samuel Guest

    Found it :)

    txtQuery.offsetLeft

    txtQuery.offsetTop

    "Samuel" <> wrote in message news:eit0g2$8tc$-com.hr...
    > Hi,
    >
    > Is it possible to get absolute position of element with javascript?
    > e.g. I have textbox somewhere in table. Textbox relative to table cell
    > position is 0,0. How can I get Textbox absolute position on page??
    > Please, any ideas, I'm going crazy...
    >
    > thanks
    >
    Samuel, Nov 8, 2006
    #2
    1. Advertising

  3. Samuel

    Samuel Guest

    AAARRRGGHHHH!!!

    It dosen't work if textbox is in table, txtQuery.offsetTop returns only
    relative to table cell....

    "Samuel" <> wrote in message news:eit0pg$9i5$-com.hr...
    > Found it :)
    >
    > txtQuery.offsetLeft
    >
    > txtQuery.offsetTop
    >
    > "Samuel" <> wrote in message news:eit0g2$8tc$-com.hr...
    >> Hi,
    >>
    >> Is it possible to get absolute position of element with javascript?
    >> e.g. I have textbox somewhere in table. Textbox relative to table cell
    >> position is 0,0. How can I get Textbox absolute position on page??
    >> Please, any ideas, I'm going crazy...
    >>
    >> thanks
    >>

    >
    >
    Samuel, Nov 8, 2006
    #3
  4. Samuel wrote:

    > It dosen't work if textbox is in table, txtQuery.offsetTop returns only
    > relative to table cell....


    Walk the offsetParent axis and add offsetTop and offsetLeft e.g.

    function getPageCoords (element) {
    var coords = { x: 0, y: 0 };
    while (element) {
    coords.x += element.offsetLeft;
    coords.y += element.offsetTop;
    element = element.offsetParent;
    }
    return coords;
    }

    var coords = getPageCoords(someElement);
    // use coords.x and coords.y here

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Nov 8, 2006
    #4
  5. Samuel

    Matt Kruse Guest

    Matt Kruse, Nov 8, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kenneth

    Absolute position of datagrid

    Kenneth, Aug 29, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,250
    Vidar Petursson
    Aug 29, 2003
  2. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    set absolute position on panel

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Mar 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,838
    Bruce Barker
    Mar 23, 2005
  3. Luqman
    Replies:
    1
    Views:
    645
    Luqman
    Feb 7, 2006
  4. Poulpy

    absolute mouse position

    Poulpy, Jun 30, 2003, in forum: Java
    Replies:
    1
    Views:
    1,508
    Wolf Martinus
    Jun 30, 2003
  5. James Byrne
    Replies:
    3
    Views:
    542
    James Byrne
    Sep 14, 2010
Loading...

Share This Page