Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery position() method

jQuery position() method

jQuery HTML/CSS methods jQuery HTML/CSS methods

Example

Return

The top and left positions of an element:

$

(

"

button

"

)

.

click

(

function

(

)

{

x

=$

(

"

p

"

)

.

position

(

)

;

alert

(

"

Top:

"

x

.

top

"

Left:

"

x

.

left

)

;

}

)

;

Try it »


Definition and Usage

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

This method returns an object with two properties (the top and left positions in pixels).


Syntax

$(

selector

).position()


More examples

Return an element's position relative to its parent
How to get the position inside the

The element is used in

element.


jQuery HTML/CSS methods jQuery HTML/CSS methods