.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
Select a parent, then call .children() (optionally with a filter).
Select the parent(s) — e.g. $("ul.level-2").
Call .children() for every direct child element.
Or pass a selector: .children(".selected") to filter.
Chain methods on the new set (.append(), .each(), …).
Remember: text nodes are skipped — use .contents() if you need them.
Piece
Required?
Role
Matched set
Yes
Parents whose children you want
selector
No
Keep 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)
Reference
Cheat Sheet
Keep these differences next to .find().
Topic
Detail
Syntax
.children([selector])
Since
jQuery 1.0
Depth
One level only
Nodes
Element nodes (not text/comments)
vs .find()
Any depth descendants
vs .contents()
Includes text & comments
DOM change?
No — query only
Try it
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.
Code
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.
Click a DIV with two kids → Found 2 children in DIV
Click a leaf SPAN → Found 0 children in SPAN
How It Works
Target.event.target is the clicked element.
Children..children() counts its direct element kids.
Report. Length and tag name go into the results line.
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);
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.
Compatibility
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 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
.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.
Analysis
Performance Notes
Approach
Cost
Best for
.children()
Cheap
Known one-level structure
.children(selector)
Cheap
Filter direct kids only
.find() deep trees
More work
When you truly need all depths
Prefer .children() when you know the structure is flat under the parent — it avoids walking an entire subtree.
Remember
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.