Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I get an elements absolute position?

0 views
Skip to first unread message

Rick

unread,
Jan 6, 2002, 2:16:05 AM1/6/02
to
I'm hosting a treeview in the broswer and I need to know the exact position
of the top left corner. I can get the information on it relative to the
client window, but I need its screen coordinates. Does anybody have any idea
on how to obtain this information?

Thanks,

Rick


Ray Ban

unread,
Jan 15, 2002, 1:56:47 AM1/15/02
to
Oh Brutus...I believe it is screen.x and screen.y

Let me know if I have erred.

--

RayBan

"...I don't believe it!", exclaimed the young Jedi apprentice.
"That" replied the Jedi master, grimly, "is why you fail".

http://www.macrospot.com
"Rick" <sand...@home.com> wrote in message
news:OMN7gGolBHA.856@tkmsftngp03...

Rick

unread,
Jan 15, 2002, 10:50:34 PM1/15/02
to
That doesn't work.

Other ideas?

Rick


"Ray Ban" <macr...@earthlink.net> wrote in message
news:PoQ08.32666$zw3.3...@newsread1.prod.itd.earthlink.net...

Ray Ban

unread,
Jan 29, 2002, 3:07:42 AM1/29/02
to
Mmm, sorry. Try, if you know the elements
position...document.all.objectId.style.left /* the objects specified left
position */ document.all.objectId.top /* the objects specified top position
*/
...alert(document.all.objectId.top); /* presuming the object has a specified
top */
...alert(document.all.objectId.left); /* presuming the object has a
specified left */

Does this help?

--

RayBan

"...I don't believe it!", exclaimed the young Jedi apprentice.
"That" replied the Jedi master, grimly, "is why you fail".

news:OVHCvCknBHA.2360@tkmsftngp02...

alec p black

unread,
Feb 2, 2002, 12:24:10 PM2/2/02
to

The following will return position of element within body of html document.
This seems to work for element embedded in and out of tables. Climbing up
the dom tree using .parentElement returned a value that accumulated too much
if the element was contained within a table. I have not been able to find a
way to determine the absolute screen position of the html document.

top = findTop(document.all.objectID);
left = findLeft(document.all.objectID);

function findTop(o) {
var nTop = o.offsetTop;

// if we are still inside the body, move up the tree
if (!o.tagName == "body")
nTop += findTop(o.offsetParent);

return nTop;
}

Create a similar function for finding the left of an object using
offsetLeft.

Rick

unread,
Feb 3, 2002, 10:12:37 PM2/3/02
to
Thanks. Through much experimentation I too have drawn the same conclusion.

Rick

"alec p black" <abl...@mindspring.com> wrote in message
news:eMtVd6ArBHA.2252@tkmsftngp03...

0 new messages