jQuery :parent Selector

Beginner
6 min read
Updated: Oct 2026
5 examples
Live preview

What Is :parent?

:parent selects every element that has at least one child node — an element or a text node. It is the inverse of :empty. Available since jQuery 1.0.

Not CSS / jQuery extension

:parent is not in the CSS spec. Prefer a CSS query first, then .filter(":parent"). Do not confuse with .parent() (upward traversal).

Remember
$(":parent")
$("td:parent")              → cells with text or elements
$(".cell").filter(":parent") → official performance pattern

<td>Value 1</td>  → matches (:parent)
<td></td>         → no match (empty)
<div> </div>      → matches (whitespace text counts)

≠ $("span").parent()  // method — climbs UP
NeedPrefer
Has children (filter)$("el:parent") / .filter(":parent")
No children$("el:empty")
Get ancestor$("el").parent()

How to Use :parent

Select candidates, then keep only those that contain at least one child node.

  1. Choose a base selector (td, .box, and so on).
  2. Add :parent, or use .filter(":parent") after a CSS query.
  3. Remember: text nodes count — even a space.
  4. Use .parent() only when you need to climb to an ancestor.
PieceRequired?Role
Base selectorUsuallyLimits which elements are tested
:parentYesKeeps elements with ≥1 child node
Child nodes—Elements or text (including whitespace)

Pseudocode

Pseudocode
candidates = find(baseSelector)
result = empty

for each el in candidates:
    if el has any child node (element or text):
        keep el

return jQuery(result)

Cheat Sheet

Keep these facts handy while filtering has-children elements.

TopicDetail
Syntax$(":parent") / $("sel").filter(":parent")
Rule≥1 child node (element or text)
Inverse:empty
vs .parent()Filter has-children vs climb upward
WhitespaceCounts as a text child
CSS?No — jQuery extension
SincejQuery 1.0

Live Preview

Run selectors on the official-style table: filled cells vs empty cells.

Official pattern: cells with “Value 1” / “Value 2” match :parent; truly empty cells match :empty.

Result
$("td:parent")
matched: 2
text: Value 1, Value 2

/* text or element children → :parent */

jQuery Examples

Short, copy-ready snippets. Open a browser console with jQuery loaded, or use Try It Yourself for a live editor.

Example 1 — Official Demo: td:parent

Find table cells that contain text or elements (jQuery API example).

jQuery
var $hits = $("td:parent");
console.log($hits.length);
console.log($hits.map(function () {
  return this.textContent.trim() || "(empty text)";
}).get().join(", "));
Try It Yourself

How It Works

  1. Select all cells. Four td elements exist in the demo table.
  2. Keep has-children. :parent keeps cells with a text child.
  3. Drop empties. Truly empty cells have zero child nodes.
  4. Official effect. The API demo fades those two cells with fadeTo.

Example 2 — :parent vs :empty

Every in-scope element is one or the other — they are inverses.

jQuery
console.log(":parent →", $(".box:parent").length);
console.log(":empty →", $(".box:empty").length);
console.log("total →", $(".box").length);
Try It Yourself

How It Works

  1. Text box. Matches :parent.
  2. Span box. Matches :parent (element child).
  3. Empty box. Matches :empty.
  4. Partition. Counts add up to the total set.

Example 3 — Whitespace Counts as a Child

A single space is a text node — so the element is :parent, not :empty.

jQuery
console.log(":parent →", $("#space:parent").length);
console.log(":empty →", $("#space:empty").length);
console.log("childNodes →", document.getElementById("space").childNodes.length);
Try It Yourself

How It Works

  1. Markup. <div id="space"> </div> holds a space character.
  2. Text node exists. childNodes.length is 1.
  3. :parent matches. Official rule: text nodes count.
  4. :empty fails. Same trap as the empty-selector tutorial.

Example 4 — Prefer .filter(":parent")

Official performance pattern: CSS select first, then filter with the extension.

jQuery
var $byPseudo = $(".cell:parent");
var $byFilter = $(".cell").filter(":parent");

console.log("same size:", $byPseudo.length === $byFilter.length);
console.log("texts:", $byFilter.map(function () {
  return this.textContent.trim();
}).get().join(", "));
Try It Yourself

How It Works

  1. CSS query. $(".cell") can use native querySelectorAll.
  2. Filter. .filter(":parent") applies the jQuery extension.
  3. Same nodes. Length matches $(".cell:parent").
  4. Official advice. Best performance pattern from the API docs.

Example 5 — :parent vs .parent()

One filters for has-children; the other climbs to an ancestor.

jQuery
console.log("li:parent →", $("li:parent").length);
console.log("span.parent() →", $("span").parent().prop("tagName"));
console.log("span.parent() text →", $("span").parent().text().trim());
Try It Yourself

How It Works

  1. li:parent. Keeps list items that contain text or a span.
  2. Empty li. Dropped — no child nodes.
  3. .parent(). From the span, climbs to its LI.
  4. Different jobs. See .parent() for upward traversal.

Edge Cases & Pitfalls

Check these before relying on :parent in real projects.

name

Not “get my parent”

:parent means “this element is a parent (has children).” Use .parent() to climb up.

text

Whitespace counts

A space or newline inside a tag makes it :parent and blocks :empty.

css

jQuery extension only

Not in querySelectorAll. Prefer $("td").filter(":parent") on large pages.

void

Void elements never match

input, img, br, hr are empty by definition — they never match :parent.

Browser Support

:parent is a jQuery extension (not CSS), available since 1.0. It works wherever jQuery runs, but cannot use native querySelectorAll alone.

✓ jQuery 1.0+ · Extension

jQuery :parent

Works in all browsers with jQuery. Not available in native querySelectorAll. Prefer .filter(':parent') after a CSS selector.

100% jQuery environments
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
:parent jQuery only

Bottom line: Use :parent for has-children filtering; use .parent() when you need to traverse up the DOM.

Performance Notes

ApproachCostBest for
$("td").filter(":parent")CSS query + filterOfficial recommended pattern
$("td:parent")Sizzle path (no QSA)Small pages / learning
$("td:empty")Native CSS possibleInverse filter (standard CSS)

Official docs: because :parent is not CSS, select with a pure CSS selector first, then filter. That lets the browser optimize the initial query.

Key Takeaways

  • Role: keep elements that have at least one child node.
  • Inverse: pairs with :empty.
  • Not .parent(): use .parent() to climb upward.
  • Perf: prefer .filter(":parent") after a CSS selector.

One line: :parent means “this element has children” — not “give me its parent.”

Frequently Asked Questions

:parent selects every element that has at least one child node — an element or a text node. $("td:parent") matches table cells that contain text or nested markup. Available since jQuery 1.0.
:empty is the inverse — elements with no children at all. Official docs describe :parent and :empty as opposites. Whitespace-only text makes an element :parent but not :empty.
Yes. Official docs: child nodes include text nodes. A div with only "Hello" (or even a single space) matches div:parent.
:parent filters the matched set for elements that have children. .parent() traverses upward to each element's immediate parent. Official docs point to .parent() / .parents() when you need ancestors.
No. :parent is a jQuery extension and cannot use querySelectorAll alone. Prefer $('.cell').filter(':parent') for performance.
No. Elements empty by definition — input, img, br, hr — never match :parent. A p with only text does match.

Next: :eq() Selector

Select a single element by its zero-based index in the matched set.

:eq tutorial →

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.

11 people found this page helpful