Skip to content
Related Articles

Related Articles

Improve Article
How to validate position in jQuery ?
  • Last Updated : 23 Apr, 2021

In this article, we will find how to validate position using jQuery position() method. The .position() method in jQuery returns the position of the first matched element relative to its parent element.



Return value:

  • Returns an object containing the properties top and left.

Example: Let us take an example to understand .position() method of jQuery.


    <script src=
<body style="text-align:center;">
    <h2 id="heading" style="color:green;">
        jQuery | .position() method
    <button id="button">
        click here to get position of heading
    // Selecting h2 tag and using .positon() method 
    // to find its position relative to offset parent.
        var x = $("h2").position();
        $( "p" ).last().text ("Top position is : " + 
      + " Left position is : " + x.left);

Output :

jQuery position method

My Personal Notes arrow_drop_up
Recommended Articles
Page :