The :parent selector matches elements that have at least one child node — an element or text. Available since jQuery 1.0; it is the inverse of :empty and a jQuery extension (not standard CSS).
01
Syntax
td:parent
02
Has children
Element or text
03
Official
td:parent
04
vs :empty
Inverse filter
05
≠ .parent()
Traversing up
06
.filter()
Performance
Fundamentals
Introduction
Tables, lists, and layout containers often mix filled cells with blank ones. jQuery’s :parent pseudo-class keeps elements that contain something inside them — nested markup or even a text node.
Official jQuery documentation describes :parent as the inverse of :empty. Both count text nodes as children, so a paragraph with only whitespace is :parent but not :empty. For climbing the DOM tree to an element’s ancestor, use the .parent() method instead — a different concept entirely.
Concept
Understanding the :parent Selector
Think of :parent as “has at least one child node”:
td:parent → cells with text like “Value 1” or nested elements.
td:empty → truly hollow cells — the complement in the same matched set.
<input>, <img>, <br> → empty by HTML definition (no children).
<p> with text → matches :parent; W3C recommends at least one child node in paragraphs.
💡
Beginner Tip
:parent does not mean “select my parent element.” It means “this element is a parent — it has children.” To get the parent of a selection, call .parent() on the jQuery object.
Foundation
📝 Syntax
Official jQuery API form (since 1.0):
jQuery
jQuery( ":parent" )
// typical usage — chain after a selector:
$( "td:parent" )
$( "div.box:parent" )
$( "li:parent" )
// performance pattern:
$( ".cell" ).filter( ":parent" )
// NOT the same as traversing up:
$( "span" ).parent() // method — returns parent elements
Parameters
No arguments — keeps elements with at least one child node (element or text).
Return value
A jQuery object containing every matching element (may be multiple).
Empty collection when no elements in scope have children.
Official jQuery API example
jQuery
// Finds all tds with children, including text
$( "td:parent" ).fadeTo( 1500, 0.3 );
Cheat Sheet
⚡ Quick Reference
Element state
:parent
:empty
<td>Value</td>
Matches
No match
<td></td>
No match
Matches
<div> </div> (space only)
Matches
No match
<div><span></span></div>
Matches
No match
Native CSS
jQuery only
Standard CSS
Compare
📋 :parent vs :empty and .parent()
Has-children filter vs inverse vs upward traversal.
:parent
td:parent
Has child nodes
:empty
td:empty
No child nodes
.parent()
$("span").parent()
Go up one level
.parents()
$("a").parents("ul")
Ancestor chain
Hands-On
Examples Gallery
Example 1 follows the official jQuery td:parent demo. Examples 2–5 compare with :empty, demonstrate the whitespace text trap, use the official .filter(':parent') pattern, and contrast with the .parent() method.
📚 Official jQuery Demo
Fade table cells that contain text or nested elements.
Example 1 — Official Demo: td:parent
Official jQuery demo — cells with “Value 1” and “Value 2” fade to 30% opacity; empty cells stay solid green.
jQuery
$( "td:parent" ).fadeTo( 1500, 0.3 );
// Only tds with child nodes (text counts) are faded
Cells A and B → filled class
Empty cell → no class
How It Works
Because :parent is not standard CSS, splitting the query helps performance on large pages.
Example 5 — Not the Same: :parent vs .parent()
Official docs — use .parent() to climb to ancestors; :parent filters for elements that have children.
jQuery
// :parent — keep li elements that contain something
console.log( "li:parent →", $( "li:parent" ).length );
// .parent() — from the span, go up to its li parent
console.log( "span.parent() →", $( "span" ).parent().prop( "tagName" ) );
li:parent → 2 (items with text or span)
span.parent() → LI (traversed upward)
How It Works
Same word, different direction — selector filters down for has-children; method traverses up the tree.
Applications
🚀 Common Use Cases
Table cells — highlight td:parent cells that contain data.
Inverse of empty — style filled containers while :empty handles hollow ones.
List cleanup — skip li:empty by selecting li:parent first.
Form validation — detect wrapper divs that received user input (text nodes).
Dynamic UI — fade or dim populated slots in dashboards.
Performance — .filter(':parent') after a CSS class query.
🧠 How jQuery Evaluates :parent
1
Build matched set
Run the selector before :parent — e.g. all td or .box.
Query
2
Inspect child nodes
Check childNodes — elements and text both count.
DOM
3
Keep non-empty
Retain elements with at least one child node — inverse of :empty.
Filter
4
✓
Return collection
Chain .fadeTo(), .css(), or other jQuery methods.
Important
📝 Notes
Available since jQuery 1.0 — inverse of :empty (official docs).
Child nodes include text nodes — whitespace prevents :empty and enables :parent.
Not standard CSS — jQuery extension only; use .filter(':parent') for performance.
Not the same as .parent() or .parents() — those traverse upward.
<input>, <img>, <br>, <hr> are empty by definition.
W3C recommends <p> have at least one child — text alone satisfies :parent.
Compatibility
Browser Support
The :parent pseudo-class is a jQuery extension — not standard CSS — and works in jQuery 1.0+. It runs in all browsers that support jQuery. Pair with standard CSS :empty for the inverse filter.
✓ jQuery 1.0+ · extension
jQuery :parent Selector
Works in all jQuery versions. Not available in querySelectorAll — use .filter(':parent') after a CSS selector.
100%jQuery only
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
:parentUniversal
Bottom line: Learn :parent for has-children filtering; use .parent() when you need to traverse up the DOM.
Wrap Up
Conclusion
The :parent selector matches elements with at least one child node — the official td:parent demo fades cells that contain text while empty cells stay solid.
Pair it with :empty, remember text nodes count, and use .parent() when you need ancestors — not a has-children filter.
Assume visually empty divs match :empty — check whitespace
Use :parent to get an element’s parent node
Forget void elements are :empty by HTML definition
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :parent
Has at least one child node.
5
Core concepts
+01
:parent
Has children
API
∅02
:empty
Inverse
Pair
txt03
Text counts
Nodes rule
Tip
↑04
.parent()
Traverse up
Compare
demo05
Official
td fade
Demo
❓ Frequently Asked Questions
:parent selects every element that has at least one child node — either 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 — it selects elements with no children at all (no elements and no text). Official jQuery docs describe :parent and :empty as opposites. Whitespace-only text makes an element :parent but not :empty.
Yes. Official docs emphasize that child nodes include text nodes. A div containing only the text "Hello" matches div:parent. This is the same rule as :empty — even a single space character prevents :empty and enables :parent.
:parent filters the matched set downward — it keeps elements that have children. .parent() traverses upward to each element's immediate parent node. Official docs point to .parent() and .parents() when you need ancestors of an existing selection, not a has-children filter.
No. :parent is a jQuery extension and does not work in native querySelectorAll. :empty is standard CSS; :parent exists only in jQuery selector strings and .filter(':parent').
Official docs: select with a pure CSS selector first, then use .filter(':parent') — e.g. $('.cell').filter(':parent') — so the browser can optimize the initial query before the jQuery extension filter runs.
Did you know?
Official jQuery docs note that <input>, <img>, <br>, and <hr> are empty by definition — they never match :parent. A <p> with only text does match, which aligns with W3C guidance that paragraphs should contain at least one child node.