THE WORLD'S LARGEST WEB DEVELOPER SITE

jQuery position() Method

❮ jQuery HTML/CSS Methods

Example

Return the top and left position of a <p> element:

$("button").click(function(){
    var x = $("p").position();
    alert("Top: " + x.top + " Left: " + x.left);
});
Try it Yourself »

Definition and Usage

The position() method returns the position (relative to its parent element) of the first matched element.

This method returns an object with 2 properties; the top and left positions in pixels.


Syntax

$(selector).position()

Examples

Try it Yourself - Examples

Return the position of an element relative to its parent element
How to get the position of a <p> element inside a <div> element.


❮ jQuery HTML/CSS Methods