Keith Bentrup
Keith Bentrup

Reputation: 11995

How can I find the position in the page of an element using jQuery?

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.

Upvotes: 4

Views: 2537

Answers (2)

Boris Guéry
Boris Guéry

Reputation: 47624

Without jQuery you can use:

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

or

document.getElementById('elemId').offsetTop
document.getElementById('elemId').offsetLeft 

Upvotes: 1

joshcomley
joshcomley

Reputation: 28838

jQuery(elem).offset();

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

Upvotes: 7

Related Questions