jQuery .children() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Traversing

Definition

.children([selector]) (since jQuery 1.0) returns the direct child elements of each matched element — one level down. Optional selector keeps only matching children. Returns a new jQuery set (chainable); does not change the DOM.

Syntax

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

jQuery
$("ul.level-2").children();           // all direct li children
$("div").children(".selected");       // only .selected children
$("ul").children("li");               // filter by tag

// children → one level (A, B, C)
// find("li") → all depths (A, B, C, 1, 2, 3)
// contents() → elements + text + comments
CallWhat it does
Matched setParents whose children you want
selectorKeep only matching direct children
DepthAlways exactly one level
Return valueNew jQuery set (element nodes only)

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

Parameters

ParameterDescription
Step 1Select the parent(s) — e.g. $("ul.level-2").
Step 2Call .children() for every direct child element.
Step 3Or pass a selector: .children(".selected") to filter.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Nested List (One Level Only)

Official idea: mark direct children of ul.level-2 — A, B, and C.

jQuery
$("ul.level-2").children().append(" [child]");
Try It Yourself

How It Works

  1. Parent. Start at ul.level-2.
  2. Direct. Only immediate li children are returned.
  3. Nested. Items inside B’s inner list are skipped.

Example 2 — All Direct Children of Each div

Official Ex. 2: every element child of every div — text nodes are ignored.

jQuery
$("div").children().append(" [child]");
Try It Yourself

How It Works

  1. Each div. $("div") may match several parents.
  2. Children. Direct element children of each are collected.
  3. Text. Bare text nodes are not returned.

Example 3 — Filter with .children(".selected")

Official Ex. 3: keep only direct children that have class selected.

jQuery
$("div").children(".selected").append(" [selected]");
Try It Yourself

How It Works

  1. All children. First consider every direct child of the div.
  2. Filter. Keep only those matching .selected.
  3. Skip. Plain paragraphs without the class are dropped.

Frequently Asked Questions

.children() returns a new jQuery object containing the direct child elements of each element in the current set — one level down the DOM tree only. An optional selector filters which child elements are included.
.children() only selects immediate children (one DOM level). .find() searches all descendants at any depth — grandchildren and deeper. Use .children() for direct offspring; use .find() to search the whole subtree.
.children() returns only element nodes (tags like li, p, div). .contents() includes text nodes, comment nodes, and elements. Use .contents() when you need raw text or mixed node types.
No. Nested elements inside a child are not selected — only direct children of each matched parent. In a nested ul, $("ul").children() returns the li elements directly under that ul, not li inside nested lists.
.children(selector) filters direct children so only those matching the selector are returned — for example, $("div").children(".selected") keeps only direct children with class selected.
No. Like other jQuery traversing methods, .children() only queries the existing DOM and returns a new collection. It does not add, remove, or move elements.

Next: .parent() Method

Walk up from an element to the nearest matching ancestor (or self).

.parent() 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