cdub
cdub

Reputation: 25711

Get the current top position of an element

I need to get a position of an element on a page from the top of the element (div) to the current position of the top of the window. I DO NOT want the position relative to the top of the page (seems offset and position are doing this?)

Upvotes: 1

Views: 1787

Answers (3)

Akhil Sekharan
Akhil Sekharan

Reputation: 12683

Try:

 var top= $('#element').offset().top+ $(document).scrollTop();

Upvotes: 1

Michael Antonius
Michael Antonius

Reputation: 972

use $(element).offset().top:

$(".element").offset().top;

and apply it to your page... Good luck

Upvotes: 0

Horen
Horen

Reputation: 11382

get the offset of the parent element, then get the offset of the child element, then substract one from the other - boom you got the information you were looking for.

Upvotes: 3

Related Questions