.position() returns the current coordinates of the first matched element as { top, left }, relative to the offset parent (since jQuery 1.2). It measures the element’s margin box against the parent’s padding box.
Remember
$("p").position() // { top: Number, left: Number }
.position() → relative to the offset parent
.offset() → relative to the document
// No setter — use .css() or .offset() to move
Read local coordinates; move with CSS when you need a write.
Select a visible DOM element.
Call .position() to get { top, left } vs the offset parent.
Use those numbers for local layout math (tooltips, neighbors, nudges).
To move the element, set position in CSS and write top/left with .css().
Piece
Required?
Role
jQuery selection
Yes
Element to measure
Arguments
—
None (getter only)
Return
—
{ top, left } (or undefined if empty)
Pseudocode
Pseudocode
function position(selection):
if selection is empty:
return undefined
el = first matched element
parent = offsetParent(el) // nearest positioned ancestor, or body
return {
top: distance from parent's padding edge to el's margin edge
left: distance from parent's padding edge to el's margin edge
}
Reference
Cheat Sheet
Keep these facts handy while reading local position.
Topic
Detail
Syntax
.position()
Since
jQuery 1.2
Returns
{ top: Number, left: Number }
Relative to
Offset parent (not the document)
Setter?
No — use .css() or .offset()
vs .offset()
Local parent vs document
Hidden elements
Not supported / unreliable
Try it
Live Preview
Pick an action and see what .position() returns inside a positioned wrapper.
Browser demo of .position() — same idea as the examples below.
Box
Result
$("#box").position()
→ { top: …, left: … }
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Get Offset-Parent Coordinates
Official style: read { top, left } for an element.
jQuery
var position = $("p").first().position();
console.log("left: " + position.left + ", top: " + position.top);
left: 10, top: 15
(Exact numbers depend on your page layout.)
How It Works
Select. Target the first paragraph with $("p").first().
Read..position() returns a plain object with top and left.
Meaning. Those numbers are distances from the offset parent.
Use. Ideal when placing something near another element in the same container.
Example 2 — .position() vs .offset()
Same element, two coordinate systems.
jQuery
var $box = $("#box");
var p = $box.position();
var o = $box.offset();
console.log("position: left " + p.left + ", top " + p.top);
console.log("offset: left " + o.left + ", top " + o.top);
Position. Ensure the element can accept top/left (relative or absolute).
Write. Apply new values with .css() — not .position().
Verify. Call .position() again to confirm the nudge.
Example 4 — Offset Parent Changes the Origin
A positioned wrapper becomes the reference for .position().
jQuery
var p = $("#box").position();
console.log("inside wrap → left " + p.left + ", top " + p.top);
console.log("offsetParent tag → " + $("#box").offsetParent()[0].tagName);
One line:.position() gives offset-parent { top, left } — read for local layout, and write moves with .css() or .offset().
Frequently Asked Questions
.position() returns { top, left } for the first matched element relative to its offset parent — the nearest positioned ancestor (or the body). It is a getter only; there is no .position({ top, left }) setter.
.position() is relative to the offset parent. .offset() is relative to the document. Use .position() for layout inside a positioned container; use .offset() for page-level placement.
Usually the closest ancestor with position relative, absolute, fixed, or sticky. If none qualify, the document body is used. That ancestor is the origin for .position().
Set CSS position (relative or absolute), then use .css({ top, left }) with values from .position() or your own numbers. For document-level moves, use the .offset() setter instead.
No. jQuery does not support reliable readings on display:none or non-rendered elements. Measure while the element is visible.
No. Values can be fractional on sub-pixel layouts or zoomed pages. Round only when your UI needs integers.