jQuery CSS Operation - position() Method

Example

Get the current position of the <p> element:

$(".btn1").click(function() {
  x=$("p").position();
  $("#span1").text(x.left);
  $("#span2").text(x.top);
});

Try It Yourself

Definition and Usage

The position() method returns the position (offset) of the matched elements relative to the parent element.

The object returned by this method contains two integer properties: top and left, measured in pixels.

This method is only effective for visible elements.

Syntax

$(selector.position()