offset() method in jquery

offest method is used to retrieve the current position of the element. It gets the coordinates of the element.It returns an object, which contains the top and left property.

<!DOCTYPE html>
<html>
<head>
  <style>
p { margin-top:20px; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js">
</script>
</head>
<body>
  <p>Mahak Garg</p><p></p>
<script>var x = $("p:last");
var offset = x.offset();
x.html( "Left Coordinate: " + offset.left + ", Top Coordinate: " + offset.top );</script>
</body>
</html>

Output:

1.png