jQuery :empty Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

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

Syntax

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

jQuery
$("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
CallWhat it does
:emptyLearn the jQuery :empty selector: match elements with no child nodes (including text), official td:empty demo, :empty vs :parent, whitespace pitfalls, browser support, and FAQs.

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

Parameters

ParameterDescription
Step 1Prefer $("td:empty") or $("div:empty") over bare $(":empty").
Step 2Remember whitespace and newlines between tags create text nodes.
Step 3Void elements (img, input, br, …) always match :empty.

Return Value

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

jQuery Examples

Example 1 — Official $("td:empty")

Find empty cells and write a placeholder into them.

jQuery
$("td:empty").text("Was empty!");

$("#out").text(
  "Filled cells: " + $("td:contains('Was empty!')").length
);
Try It Yourself

How It Works

  1. Select. $("td:empty") finds cells with no children.
  2. Write. .text("Was empty!") fills only that set.
  3. Skip. Cells that already had text stay unchanged.

Example 2 — :empty vs :parent

Official pair: :empty is the inverse of :parent.

jQuery
$("#out").text(
  "td:empty → " + $("td:empty").length + "\n" +
  "td:parent → " + $("td:parent").length
);
Try It Yourself

How It Works

  1. Empty. Cells with zero child nodes.
  2. Parent. Cells that contain text or elements.
  3. Split. On a six-cell table, counts often add up.

Example 3 — Whitespace Is Not Empty

A space or newline inside a tag creates a text node.

jQuery
$("#out").text(
  "Truly empty: " + $("#a:empty").length + "\n" +
  "Has space: " + $("#b:empty").length + "\n" +
  "#b is :parent? " + $("#b").is(":parent")
);
Try It Yourself

How It Works

  1. #a. <div id="a"></div> has no child nodes → empty.
  2. #b. A space between tags is a text node → not empty.
  3. Parent. That space makes #b match :parent.

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.

Next: :parent Selector

Learn the inverse of :empty — elements that have at least one child.

:parent Selector 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.

8 people found this page helpful