Saturday, June 13, 2026
HomeLanguagesJavascriptjQuery position() Method

jQuery position() Method

The position() method is an inbuilt method in jQuery that is used to find the position of the first matched element relative to its parent element in the DOM tree.

Syntax:  

$(selector).position()

Parameters: This method does not contain any parameters.

Return Value: This method returns the position of the first matched element.

Example:  In this example, we are using the jQuery position() method.

html




<!DOCTYPE html>
<html>
 
<head>
    <title>The position Method</title>
    <script src=
    </script>
 
    <!-- jQuery code to show the working of this method -->
    <script>
        $(document).ready(function () {
            $("button").click(function () {
                let x = $("p").position();
                alert("Top position: " + x.top);
            });
        });
    </script>
    <style>
        body {
            display: flex;
            justify-content: center;
        }
 
        div {
            width: 350px;
            height: 100px;
            font-weight: bold;
            padding: 20px;
            font-size: 25px;
            border: 2px solid green;
        }
    </style>
</head>
 
<body>
    <div>
 
        <p>neveropen.</p>
        <!-- Click on this button  -->
        <button>Click Here!</button>
    </div>
</body>
 
</html>


Output: 
jquery-20
Related Articles: 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS