:empty (since jQuery 1.0) selects elements that have no children at all — no element nodes and no text nodes. It is the inverse of :parent and is a standard CSS pseudo-class.
Remember
$("td:empty") // empty table cells
$("div:empty") // empty divs (no text, no kids)
$(":empty") // avoid — scans every element
// <div></div> → :empty ✓
// <div> </div> → NOT empty (whitespace text node)
// :parent → inverse of :empty
Prefix with a tag, then decide what to do with truly empty nodes.
Prefer $("td:empty") or $("div:empty") over bare $(":empty").
Remember whitespace and newlines between tags create text nodes.
Void elements (img, input, br, …) always match :empty.
Use :parent when you want the opposite set.
To clear content in code, call .empty() — that is a method, not this selector.
Piece
Required?
Role
:empty
Yes
Matches nodes with zero children
Tag prefix
Recommended
Avoids a universal * scan
Text nodes
—
Count as children (including spaces)
Return value
—
jQuery collection of matching elements
Pseudocode
Pseudocode
matches = []
for each element in search context:
if element.childNodes.length === 0:
matches.add(element)
return matches
// Note: a single whitespace text node → length 1 → NOT empty
Reference
Cheat Sheet
Keep these facts handy when checking for empty nodes.
Topic
Detail
Syntax
$("td:empty")
Since
jQuery 1.0 · CSS standard
Children
Elements and text nodes
Inverse
:parent
Whitespace
Makes an element non-empty
Void tags
img, input, br, … always empty
Bare form
Avoid $(":empty")
Method twin
.empty() clears contents
Try it
Live Preview
Run td:empty on a mini table like the official demo.
Sample table
TD #0
TD #2
TD#5
Official idea: find cells with no children, then write text into them.
Result
$("td:empty").length
→ 3
empty cells → 3
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Official $("td:empty")
Find empty cells and write a placeholder into them.
One line::empty finds nodes with no children — including no text — so keep tags tight and prefix with a tag name.
Frequently Asked Questions
:empty matches elements that have no children — no element nodes and no text nodes. $("td:empty") finds table cells with nothing inside. Available since jQuery 1.0.
:parent is the inverse — it selects elements that have at least one child (element or text). If a div contains only whitespace text, it matches :parent but not :empty.
Bare :empty implies the universal selector — equivalent to $("*:empty"), which scans every element type. Prefer $("td:empty"), $("div:empty"), or $("#panel li:empty").
Yes. A text node — even a single space or newline between tags — counts as a child. <div> </div> does not match :empty; <div></div> does.
Void elements like img, input, br, and hr have no children by definition, so they always match :empty.
Yes. :empty is a standard CSS pseudo-class. jQuery has supported it since 1.0. Prefer a tag prefix for clarity and performance.