jQuery

What is the difference between jquery position() and offset()?

<html>
<body>
<divid="div1"style="position:absolute; top:50px; left:50px">
<divid="div2">
</div>
</div>
</body>
</html>


Both offset and position for body will return 0 and 0.
Both offset and position for div1 will return 50 and 50.

AND NOW THE INTERESTING PART

Position for div2 will return top:0 and left:0 which would be relative to the parent in this case div1.
HOWEVER,
Offset for div2 will return top:51 and left:51 which is relative to the body and 1 is added to 50 for 1px border.

Advertisements