Reputation: 2915
I am trying to get the top
of a div element whose position is relative. So the structure is something similar to :
<div class="head"></div>
<div class="main"></div>
<div class="foot"></div>
div { position : relative; }
Now i tried :
$(".foot").css("top") => auto
$(".foot").offset().top => This gives value but that value is
not matching the current top position of the foot div
What i am missing here?
Upvotes: 2
Views: 3478
Reputation: 18556
How about $('.foot').position().top
? this gives you the position relative to the parent DOM element
Upvotes: 1
Reputation: 16190
Use .offsetTop
.
Demo. I make the window automatically scroll to the top of the div
Upvotes: 2