jQuery position() Method

jQuery position() method sets or returns the current coordinates of the selected elements, relative to the offset parent.

Contrast position() method with offset() method, which retrieves the current position relative to the document.

Syntax

Here is a syntax for position() method

$(selector).position();

The position() method does not accept any arguments.

Example

Here, in this example call position() method

<!DOCTYPE html>
<html>
<head>
  <title>jQuery position() method</title>
  <script src="jquery-latest.min.js"></script>
  <script>
    $(document).ready(function() {
      $("button").click(function(){
        var Page = $("p").position();
        $("span").text("Left Position: " + Page.left + ", Top Position: " + Page.top);
      });
    });
  </script>
</head>
<body>
  <p>First paragraph star here</p>
  <button>Click here to call position() method</button>
  <br />
  <span></span>
</body>
</html>

Run it...   »