HTML elements' coordinates

Hi,
how can I get the absolute positions of the corners of an HTML element ?

Comments

  • Palgiarised from http://www.quirksmode.org/index.html?/js/findpos.html:

    [code]function findPosX(obj)
    {
    var curleft = 0;
    if (obj.offsetParent)
    {
    while (obj.offsetParent)
    {
    curleft += obj.offsetLeft
    obj = obj.offsetParent;
    }
    }
    else if (obj.x)
    curleft += obj.x;
    return curleft;
    }

    function findPosY(obj)
    {
    var curtop = 0;
    if (obj.offsetParent)
    {
    while (obj.offsetParent)
    {
    curtop += obj.offsetTop
    obj = obj.offsetParent;
    }
    }
    else if (obj.y)
    curtop += obj.y;
    return curtop;
    }[/code]
    ^D
    $ shameless-plug
    http://line-ed.sourceforge.net

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion