jQuery .children() Method

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

What Is .children()?

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

Remember
$("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
NeedUse
Direct children only$el.children()
Any-depth descendants.find()
Children + text nodes.contents()
Go up one level.parent()
CSS child combinator$("ul > li")

How to Use .children()

Select a parent, then call .children() (optionally with a filter).

  1. Select the parent(s) — e.g. $("ul.level-2").
  2. Call .children() for every direct child element.
  3. Or pass a selector: .children(".selected") to filter.
  4. Chain methods on the new set (.append(), .each(), …).
  5. Remember: text nodes are skipped — use .contents() if you need them.
PieceRequired?Role
Matched setYesParents whose children you want
selectorNoKeep only matching direct children
Depth—Always exactly one level
Return value—New jQuery set (element nodes only)

Pseudocode

Pseudocode
call $(parents).children(selector?)

result = empty set
for each parent in the matched set:
    for each direct child element of parent:
        if no selector OR child matches selector:
            add child to result

return result as a new jQuery object
(text/comment nodes are never included)

Cheat Sheet

Keep these differences next to .find().

TopicDetail
Syntax.children([selector])
SincejQuery 1.0
DepthOne level only
NodesElement nodes (not text/comments)
vs .find()Any depth descendants
vs .contents()Includes text & comments
DOM change?No — query only

Live Preview

Run .children() or .find("li") on the sample list and compare counts.

  • A
  • B
    • 1
    • 2
    • 3
  • C

children → A, B, C (3). find("li") → A, B, C, 1, 2, 3 (6).

Result
Ready — choose a method and click Run.

jQuery Examples

Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.

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.
  4. Mark. Append runs on A, B, and C only.

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.
  4. Mark. Only p, span, and similar tags are tagged.

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.
  4. Still one level. Nested matches deeper down are not searched.

Example 4 — Click to Count Children

Official Ex. 1 pattern: on click, report how many direct children the target has.

jQuery
$("#container").on("click", function (event) {
  var kids = $(event.target).children();
  $("#results").text(
    "Found " + kids.length + " children in " + event.target.tagName
  );
  event.preventDefault();
});
Try It Yourself

How It Works

  1. Target. event.target is the clicked element.
  2. Children. .children() counts its direct element kids.
  3. Report. Length and tag name go into the results line.
  4. Leaves. Elements with no child tags report 0.

Example 5 — .children() vs .find()

Same list, different depth — compare the li counts.

jQuery
var c = $("ul.level-2").children("li").length;
var f = $("ul.level-2").find("li").length;
$("#out").text("children('li'): " + c + "\nfind('li'): " + f);
Try It Yourself

How It Works

  1. children. Counts A, B, C only.
  2. find. Also includes nested 1, 2, 3.
  3. Filter. Both use "li" — depth is the difference.
  4. Pick. Use children when depth must stay one level.

Edge Cases & Pitfalls

Common mix-ups when counts look “too small.”

depth

Grandchildren are never included

If you need nested matches, switch to .find().

text

Text nodes are skipped

Loose text inside a parent is not a child element. Use .contents() for those nodes.

filter

Selector still stays one level

.children(".x") does not search deeper for .x — only direct kids.

empty

No children → empty set

Leaf elements return .length === 0. That is expected, not an error.

css

$("ul > li") is similar, not identical API

The child combinator is a selector string; .children() is a method on an existing set — useful when you already have the parent in a variable.

Browser Support

.children() has been part of jQuery since 1.0. It works in every browser that runs your loaded jQuery version — no separate browser feature flag.

✓ Stable · jQuery 1.0+

jQuery .children()

Supported across jQuery 1.x, 2.x, and 3.x. Prefer a current jQuery 3.x build. Traversal uses the live DOM tree.

100% With jQuery
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
.children() Universal

Bottom line: Safe for menus, lists, and one-level panels. Reach for .find() when depth matters, and .contents() when you need text nodes.

Performance Notes

ApproachCostBest for
.children()CheapKnown one-level structure
.children(selector)CheapFilter direct kids only
.find() deep treesMore workWhen you truly need all depths

Prefer .children() when you know the structure is flat under the parent — it avoids walking an entire subtree.

Key Takeaways

  • Role: direct child elements — one level down — since jQuery 1.0.
  • Filter: optional selector keeps matching children only.
  • vs find: .find() goes any depth; .children() does not.
  • Nodes: elements only — use .contents() for text/comments.

One line: .children() grabs immediate element kids — never grandchildren.

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: .closest() Method

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

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

10 people found this page helpful