jQuery Child Selector

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

What Is parent > child?

The child combinator parent > child (since jQuery 1.0) selects only direct children of a parent. It is a more specific form of the descendant combinator (parent child), which matches at any nesting depth. Official docs call it a standard CSS combinator.

Remember
$("ul.topnav > li")   // direct li only
$("ul.topnav li")     // every li inside (any depth)

$("div > span")       // spans that are immediate children
$("nav > ul > li > a") // chain one level at a time

// Equivalent traversal: $(parent).children(child)
NeedUse
Direct children only$("parent > child")
Any nesting depth$("parent child")
From a jQuery object.children("child")
First child among siblings:first-child
Nth child among siblings:nth-child()

How to Use parent > child

Name the parent, then the child type you want at the next level only.

  1. Write a parent selector (id, class, or tag) on the left of >.
  2. Write a child selector on the right — only matching immediate children are kept.
  3. Chain more > steps when you need a fixed depth (e.g. nav > ul > li > a).
  4. Prefer > over a space when nested markup could match too many elements.
  5. If you already have a jQuery set, .children() does the same job as a method.
PieceRequired?Role
parentYesAny valid selector for the parent elements
>YesChild combinator (direct children only)
childYesFilter applied to each parent’s immediate children
Return value—jQuery collection of matching child elements

Pseudocode

Pseudocode
matches = []
for each parentElement matching "parent":
    for each childElement of parentElement.children:   // first level only
        if childElement matches "child":
            matches.add(childElement)

return matches

// Contrast — descendant (space):
// walk ALL nested descendants, not just .children

Cheat Sheet

Keep these facts handy when choosing between > and a space.

TopicDetail
Syntax$("parent > child")
SincejQuery 1.0 · CSS standard
DepthFirst-level children only
vs spaceparent child = any depth
Chaina > b > c = one level per step
Method twin$(parent).children(child)
Empty setNo direct match → length 0
WhitespaceSpaces around > are optional

Live Preview

Run ul.topnav > li vs ul.topnav li on the same nested list and compare match counts.

Sample menu

  • Item 1
  • Item 2
    • Nested item 1
    • Nested item 2
    • Nested item 3
  • Item 3

Same idea as the official jQuery ul.topnav > li demo — nested items are skipped by >.

Result
$("ul.topnav > li").length
→ 3

matched → Item 1, Item 2, Item 3

jQuery Examples

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

Example 1 — Official ul.topnav > li

Mark only top-level list items — nested sub-list items are skipped.

jQuery
var labels = [];
$("ul.topnav > li").each(function () {
  var text = $.trim(
    $(this).contents().filter(function () {
      return this.nodeType === 3;
    }).text()
  );
  labels.push(text || "Item");
});

$("#out").text(
  "Direct: " + labels.join(" | ") + "\n" +
  "Skipped nested count: " + ($("ul.topnav li").length - labels.length)
);
Try It Yourself

How It Works

  1. Parent. ul.topnav is the menu container.
  2. Combinator. > keeps only that ul’s immediate li children.
  3. Skip. Nested li elements under the inner ul do not match.
  4. Result. Three top-level items are selected — same as the official demo.

Example 2 — Child vs Descendant Count

Same markup, two selectors — see how depth changes the match count.

jQuery
var direct = $("ul.topnav > li").length;
var all = $("ul.topnav li").length;

$("#out").text(
  "Direct children (>): " + direct + "\n" +
  "All descendants (space): " + all
);
Try It Yourself

How It Works

  1. Direct. > counts the three top-level li elements.
  2. Descendant. A space also includes the three nested items → 6.
  3. Rule. Use > when nesting must not inflate your set.
  4. Check. Logging both counts is a quick way to catch over-matching.

Example 3 — div > span Only

Select spans that sit directly under #content, not inside wrappers.

jQuery
$("#content > span").each(function () {
  $(this).text($(this).text() + " (direct)");
});

$("#out").text(
  "Direct spans: " + $("#content > span").length +
  " | All spans: " + $("#content span").length
);
Try It Yourself

How It Works

  1. Structure. One span is a child of #content; another sits inside #inner.
  2. Filter. #content > span keeps only the direct span.
  3. Label. We append (direct) so you can see which matched.
  4. Compare. #content span would still match both.

Example 4 — Chained nav > ul > li > a

Walk one level at a time to grab primary nav links — not dropdown links.

jQuery
var labels = [];
$("nav.main > ul > li > a").each(function () {
  labels.push($(this).text());
});

$("#out").text("Top links: " + labels.join(", "));
Try It Yourself

How It Works

  1. Step 1. nav.main > ul — the menu’s direct list.
  2. Step 2. That ul’s direct li children.
  3. Step 3. Each of those li’s direct a children.
  4. Skip. Links inside nested dropdown uls never match.

Example 5 — Main Table Rows Only

Select rows in the outer tbody — ignore rows inside a nested table.

jQuery
var rows = [];
$("table.data > tbody > tr").each(function (i) {
  rows.push("Row " + (i + 1));
});

$("#out").text(
  "Main rows: " + rows.join(", ") +
  " | All tr in table: " + $("table.data tr").length
);
Try It Yourself

How It Works

  1. Path. table.data > tbody > tr requires each step to be a direct child.
  2. Outer rows. Both main data rows match.
  3. Nested. A tr inside an inner table is not a child of the outer tbody.
  4. Why it matters. Tables-in-tables are a classic place where a space selector over-matches.

Edge Cases & Pitfalls

Check these before relying on > in nested layouts.

depth

Space vs >

parent child walks every level. parent > child stops at the first. Menus and nested tables are common false-match sources.

text

Text nodes are not elements

Whitespace or plain text between tags is not a child element. > only considers element children.

wrapper

Extra wrappers break the chain

If markup adds a div between nav and ul, nav > ul returns empty. Inspect the real DOM tree first.

method

.children() is the method twin

Prefer .children() when you already hold a jQuery object and want to filter its direct children without rebuilding a full selector string.

Browser Support

The parent > child combinator is standard CSS and has been in jQuery since 1.0. It works wherever your jQuery build runs.

✓ Stable · CSS · jQuery 1.0+

jQuery parent > child

Supported across jQuery 1.x, 2.x, and 3.x in every browser that runs your jQuery build. Prefer current jQuery 3.x for modern projects.

100% CSS combinator support
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
parent > child Universal

Bottom line: Safe everywhere jQuery runs. Prefer a specific parent (id/class) so the query stays fast and readable.

Performance Notes

ApproachCostBest for
$("#id > child")CheapestKnown container + direct children
$("ul.menu > li")CheapTypical menus and lists
$("div span") (deep)HigherOnly when any depth is required
$(el).children()CheapAlready holding a jQuery object

> is usually cheaper than a deep descendant walk because it only inspects first-level children. Start from a specific parent when you can.

Key Takeaways

  • Role: parent > child matches direct children only.
  • vs space: a space matches any depth — use it only when you mean that.
  • Chain: a > b > c walks one fixed level per step.
  • Method: pair with .children() when you already have a set.

One line: use parent > child when you mean “one level down” — not every nested match.

Frequently Asked Questions

The child combinator (parent > child) selects only direct children of a parent. $("ul.topnav > li") matches top-level list items inside ul.topnav, but not li elements nested inside a sub-list.
A space is the descendant combinator — it matches at any nesting depth. The > combinator matches only first-level children. $("div span") finds every span inside div; $("div > span") finds only spans that are immediate children of div.
Yes. $("nav > ul > li > a") walks one level at a time — a direct ul under nav, that ul’s direct li children, and each li’s direct a children. Use this when you need a precise depth.
Both target direct children. $("parent > child") is a CSS selector string for one-shot queries. .children("child") is a traversal method — useful when you already have a jQuery object and want its immediate children.
Yes. The > combinator is standard CSS (Selectors Level 3) and has been in jQuery since 1.0. Prefer specific parents like $("ul.topnav > li") over overly broad queries.
Use > when nested markup could cause false matches — menus with sub-menus, tables inside tables, or cards with inner wrappers. Direct-child selection keeps the query precise.

Next: :first-child Selector

Learn how to match the first child among siblings with :first-child.

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

8 people found this page helpful