The position() method is an inbuilt method in jQuery which 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 contains any parameters.
Return Value: This method returns the position of the first matched element.
Below example illustrate the position() method in jQuery:
Example:
<!DOCTYPE html> <html> <head> <title>The position Method</title> <script src= </script> <!-- jQuery code to show the woirking of this method --> <script> $(document).ready(function(){ $("button").click(function(){ var x = $("p").position(); alert("Top position: " + x.top); }); }); </script> <style> div { width: 350px; height: 100px; font-weight: bold; padding:20px; font-size: 25px; border: 2px solid green; } </style> </head> <body> <div> <p>GeeksforGeeks.</p> <!-- Click on this button --> <button>Click Here!</button> </div> </body> </html> |
Output:
Before click on the button:

After click on the button:

Related Articles:
Recommended Posts:
- jQuery UI | position() Method
- What is the difference between position() and offset() in jQuery ?
- How to get position of an element relative to the document or parent using jQuery ?
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- jQuery | prepend() with Examples
- jQuery | dblclick() with Examples
- jQuery | offset() with Examples
- jQuery | children() with Examples
- jQuery | Hide/Show, Toggle and Fading methods with Examples
- jQuery | focusin() with Examples
- jQuery | Animation, Slide methods with Examples
- jQuery | change() with Examples
- jQuery | filter() with Examples
- jQuery | height() and innerHeight() with Examples
- jQuery | eq() with Examples
- jQuery | empty() with Examples
- jQuery | not() method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


