views:

190

answers:

2

I'm aware of the position method, but that retrieves the position relative to the offset parent. Do I just throw in a loop to transverse up the document nodes?

I guess that I'm surprised that it isn't part of the core, and I'm wondering if it's tucked away somewhere that I don't know about.

+6  A: 
jQuery(elem).offset();

See http://docs.jquery.com/CSS/offset for a summary

joshcomley
thanks. i was pretty sure it was in there. i kept looking under the transversing section.
Keith Bentrup
+1  A: 

Without jQuery you can use:

document.getElementById('elemId').clientTop
document.getElementById('elemId').clientLeft

or

document.getElementById('elemId').offsetTop
document.getElementById('elemId').offsetLeft
Boris Guéry
clientLeft and clientTop are IE only.Other browsers use offsetLeft and offsetTop, but jQuery nicely wraps up all the inconsistencies for you
joshcomley
Didn't know about that, because i just tried to retrieve this with Firebug and works. I edit my post so other people will know about it... Thanks for the tip
Boris Guéry