Example

Get the current position of a p element:

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

Try it yourself »

Definition and Usage

The position() method returns the position of the first selected element, relative to the parent element.

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

Syntax

$(selector).position()


Examples

Try it Yourself - Examples

Get the position of an element inside another element
How to get the position of a p element inside a div element.