.position()
Categories: Style Properties | CSS | UI | Offset
.position()Returns: Object
Description: Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.
-
.position()
version added: 1.0
The .position()
method allows us to retrieve the current position of an element relative to the offset parent. Contrast this with .offset()
, which retrieves the current position relative to the document. When positioning a new element near another one and within the same containing DOM element, .position()
is the more useful.
Returns an object containing the properties top
and left
.
Note that jQuery does not support getting the position coordinates of hidden elements.
-
Access the position of the second paragraph:
HTML:
<div> <p>Hello</p> </div> <p></p>
CSS:
div { padding: 15px;} p { margin-left:10px; }
Code:
var p = $("p:first"); var position = p.position(); $("p:last").text( "left: " + position.left + ", top: " + position.top );
.position( [ options ] )
Plugin: jQuery.ui.position
Description: Apply the Position widget for each element in the set of matched elements
-
.position( [ options ] )
version added: 1.0options A map of additional options pass to the widget.
Utility script for positioning any widget relative to the window, document, a particular element, or the cursor/mouse.
Note: jQuery UI does not support positioning hidden elements.
Does not need ui.core.js or effects.core.js.