Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Getting DOM element position(style.left and

Thread Tools

Getting DOM element position(style.left and

Amir Hardon
Posts: n/a
I'm sorry for the RTFM question, but these keywords are too
common for being usefull with google.

I'm trying to position a dynamically created DOM element
(with style.position=absolute), in a position relative to
another element which don't have an absolute position,
My problem is getting the "absolute" position of that element.

I wrote two function(below) to solve this problem,
but I'm pretty sure there is a more effective solution:

function getoffsetLeft(element){/* Calculate the offsetLeft sum of all
The result is
if(!element) return 0;
return element.offsetLeft + getoffsetLeft(element.offsetParent);

function getoffsetTop(element){/* Calculate the offsetTop sum of all
The result is
if(!element) return 0;
return element.offsetTop + getoffsetTop(element.offsetParent);
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
getting DOM element from absolute coordinates wolverine Javascript 12 02-26-2008 07:38 AM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
set dom element class (if element was dynamically created) ted benedict Javascript 3 01-27-2006 01:29 AM
Getting a DOM element's children by type (STUPID) Tom Anderson Python 2 06-10-2005 05:50 PM
getting a specific element in DOM W3C Ricardo Garcia Javascript 1 09-21-2004 12:16 PM