jQuery position()Method

jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Examples

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

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

Try it yourself »

Definition and Usage

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

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


Syntax

$(selector).position()


实例

More 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 方法jQuery HTML/CSS Methods

Other Extensions