jQuery .parent() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Traversing

Definition

.parent([selector]) (since jQuery 1.0) returns the immediate parent of each matched element — one level up. Optional selector keeps the parent only if it matches. Returns a new jQuery set; does not change the DOM.

Syntax

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

jQuery
$("li.item-a").parent();              // wrapping ul
$("p").parent(".selected");           // parent only if .selected
$(this).parent();                     // common in click handlers

// parent()   → one level up (direct parent)
// parents()  → all ancestors
// closest()  → nearest match (incl. self)
// children() → one level down
CallWhat it does
Matched setChild element(s)
selectorKeep parent only if it matches
DepthAlways exactly one level up
Return valueNew jQuery set (0 or 1 per start, after unique)

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

Parameters

ParameterDescription
Step 1Select the child element(s) — e.g. $("li.item-a").
Step 2Call .parent() to get each one’s immediate parent.
Step 3Or pass a selector: .parent(".selected") to filter.

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

Example 1 — Parent of Item “A”

Official idea: from li.item-a, mark the wrapping ul.

jQuery
$("li.item-a").parent().append(" [parent]");
Try It Yourself

How It Works

  1. Start. Select li.item-a.
  2. Up one. Immediate parent is the inner ul.
  3. Stop. No further ancestors are visited.

Example 2 — Prepend Each Element’s Parent Tag

Official Ex. 1 idea: show PARENT > before each element in body.

jQuery
$("*", document.body).each(function () {
  var parentTag = $(this).parent().get(0).tagName;
  $(this).prepend(document.createTextNode(parentTag + " > "));
});
Try It Yourself

How It Works

  1. Scan. Every element under document.body.
  2. Parent. Read that node’s immediate parent tag.
  3. Prepend. Insert TAG > as text at the start.

Example 3 — Parent With Class selected

Official Ex. 2 idea: keep the parent only when it has class selected.

jQuery
$("p").parent(".selected").append(" [selected parent]");
Try It Yourself

How It Works

  1. Children. Select every p.
  2. Up. Look at each paragraph’s immediate parent.
  3. Filter. Keep the parent only if it matches .selected.

Frequently Asked Questions

.parent() returns the immediate parent element of each node in the current collection — one level up the DOM tree. An optional selector filters the parent so it is included only when it matches.
.parent() moves up exactly one level — the direct parent only. .parents() collects every ancestor up to the document root. From a nested li, .parent() gives the containing ul; .parents("ul") can return multiple ul ancestors.
.parent() returns only the immediate parent — no further. .closest(selector) walks up from the element itself (including self) until the first selector match. Use .parent() for the direct parent; use .closest() when the match may be higher or include self.
.parent() goes up one level; .children() goes down one level. They are mirror methods — parent is who wraps you; children are what you directly wrap.
With .parent(selector), the immediate parent is tested. If it does not match, that start contributes nothing — jQuery does not walk to grandparents. Use .parents(selector) or .closest(selector) for a higher ancestor.
No. Like other jQuery traversing methods, it only queries the existing DOM and returns a new collection.

Next: .parents() Method

Walk up and collect every ancestor — not just the immediate parent.

.parents() Method 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.

10 people found this page helpful