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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s