jQuery .position() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
CSS

Definition

.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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("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
CallWhat it does
.position()Learn jQuery .position(): get { top, left } relative to the offset parent, compare with .offset(), move with .css() (no setter), examples, pitfalls, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select a visible DOM element.
Step 2Call .position() to get { top, left } vs the offset parent.
Step 3Use those numbers for local layout math (tooltips, neighbors, nudges).

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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);
Try It Yourself

How It Works

  1. Select. Target the first paragraph with $("p").first().
  2. Read. .position() returns a plain object with top and left.
  3. Meaning. Those numbers are distances from the offset parent.

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);
Try It Yourself

How It Works

  1. Parent. .position() measures from the offset parent.
  2. Document. .offset() measures from the page origin.
  3. Why both? Nested layout needs parent coords; overlays often need document coords.

Example 3 — Move with .css() (No Setter)

Read .position(), then write top/left yourself.

jQuery
var $box = $("#box");
var p = $box.position();

$box.css({
  position: "relative",
  top: p.top + 20,
  left: p.left + 10
});

var next = $box.position();
console.log("left: " + next.left + ", top: " + next.top);
Try It Yourself

How It Works

  1. Read. Capture the current local coordinates.
  2. Position. Ensure the element can accept top/left (relative or absolute).
  3. Write. Apply new values with .css() — not .position().

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.

Next: scrollLeft() Method — Horizontal Scroll

Learn how to read and set horizontal scroll position.

scrollLeft() Method — Horizontal Scroll tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful