By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

Exact Location of an Element

P: n/a
This must have been covered a million times, but I'll be damned if I can
find the right information. Right now I'm using the following code:

This is a function to recusively calculate the absolute position of an
object (because you can't do it directly?):

SomeObject.prototype.__calcOffset__ = function (node) {
if (node && node.offsetTop)
return node.offsetTop + this.__calcOffset__(node.offsetParent);
else
return 0;
}

The problem is that while it worked in a simple layout it's not working
well in other layouts. Any ideas?

Brett
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Brett Foster wrote:
This must have been covered a million times, but I'll be damned if I can
find the right information. Right now I'm using the following code:

This is a function to recusively calculate the absolute position of an
object (because you can't do it directly?):

SomeObject.prototype.__calcOffset__ = function (node) {
if (node && node.offsetTop)
return node.offsetTop + this.__calcOffset__(node.offsetParent);
else
return 0;
}

The problem is that while it worked in a simple layout it's not working
well in other layouts. Any ideas?

Brett


Have a look here:

<URL:http://www.quirksmode.org/js/findpos.html>

and play with offsetParent.
--
Fred
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.