The child selector uses the > combinator to match direct children only — not grandchildren or deeper descendants. Available since jQuery 1.0; ideal for navigation menus, nested lists, and any markup where depth matters.
01
Syntax
parent > child
02
Direct
First level only
03
Official
ul.topnav > li
04
vs Space
Descendant
05
Chain
nav > ul > li
06
CSS
Standard combinator
Fundamentals
Introduction
Real HTML is nested — lists inside lists, divs inside divs, tables inside tables. When you write $("ul li"), jQuery matches every list item at any depth. Sometimes that is what you want; often it is not.
The child combinator > narrows the search to immediate children only. Official jQuery documentation describes it as a more specific form of the descendant combinator: it selects first-level descendants and stops there. This tutorial walks through the official ul.topnav > li demo and practical patterns you will use in menus, layouts, and data tables.
Concept
Understanding the Child Selector
Think of parent > child as a one-step relationship: “Is this element a direct child of that parent?”
ul.topnav > li → top-level items only; nested sub-list items are skipped.
div > span → spans whose parent is a div; spans inside nested divs may not match.
nav > ul > li → walk the tree one level at a time.
💡
Beginner Tip
If your selector accidentally styles nested elements, try replacing the space with >. The space means “any descendant”; > means “direct child only.”
parent — any valid selector for the parent element(s).
child — a selector to filter the direct child elements.
Return value
A jQuery object containing every element that is a direct child of a matched parent.
Deeper descendants are excluded even if they match the child selector.
Official jQuery API example
jQuery
// Places a border around all list items that are direct children of ul.topnav
$( "ul.topnav > li" ).css( "border", "3px double red" );
Cheat Sheet
⚡ Quick Reference
Markup relationship
parent > child
parent child (space)
Direct child of parent
Matches
Matches
Grandchild (nested one level deeper)
No match
Matches
Great-grandchild or deeper
No match
Matches
Same element type, wrong parent
No match
No match (unless ancestor exists)
Compare
📋 Child (>) vs Descendant (space)
Same parent and child tags — different depth rules.
Child
ul.topnav > li
Top-level items only
Descendant
ul.topnav li
All items at any depth
Chained child
nav > ul > li
Precise depth path
.children()
$("#nav").children("li")
Traversal equivalent
Hands-On
Examples Gallery
Example 1 follows the official jQuery ul.topnav > li demo. Examples 2–5 compare child vs descendant selectors, style direct spans, target top-level nav links, and select table body rows. Use the Try-it links to run each snippet.
📚 Official jQuery Demo
Border only direct list items — nested sub-list items stay untouched.
Example 1 — Official Demo: ul.topnav > li
Official jQuery demo — add a double red border to top-level navigation items only.
jQuery
$( "ul.topnav > li" ).css( "border", "3px double red" );
// Item 2 contains a nested ul — those inner li elements are NOT matched
The nested <ul> inside Item 2 creates a second level. Only li elements whose parent is ul.topnav match — inner list items have a nested ul as parent instead.
Example 2 — Count > vs Descendant Matches
Compare how many list items each combinator finds in the same menu.
jQuery
console.log( "Direct children:", $( "ul.topnav > li" ).length );
console.log( "All descendants:", $( "ul.topnav li" ).length );
// > = 3 top-level items; space = 6 items including nested ones
Home, Products, Contact → class "top-link"
Sub-link A, Sub-link B in dropdown → no class
How It Works
Chaining > at each level documents the exact DOM path. Dropdown anchors sit inside a nested ul, so they fail the li > a direct-child test at the top level.
Example 5 — Table Body Rows: table.data > tbody > tr
Select direct rows of the main tbody — avoid rows inside nested tables.
jQuery
$( "table.data > tbody > tr" ).addClass( "data-row" );
// Rows inside a nested table within a cell are not matched
Row 1, Row 2 → class "data-row"
Nested table rows → no class
How It Works
Nested tables place rows inside an inner tbody, not the outer table’s direct tbody. The child combinator keeps your row selection scoped to the main data grid.
Applications
🚀 Common Use Cases
Navigation menus — style top-level items without affecting dropdown sub-items.
Nested lists — count or highlight only first-level li elements.
Card grids — select direct column children in a flex or grid container.
Form sections — target inputs that are immediate children of a fieldset.
Data tables — operate on main tbody rows, skip nested detail tables.
Component shells — apply layout rules to direct wrapper children only.
🧠 How jQuery Evaluates parent > child
1
Find parents
jQuery first matches every element that satisfies the parent part of the selector.
Parent
2
Inspect children
For each parent, look at immediate child nodes only — not deeper descendants.
Depth
3
Filter by child
Keep children that match the child selector string.
Filter
4
✓
Return collection
Matched direct children become a jQuery object for chaining.
Important
📝 Notes
Available since jQuery 1.0 — standard CSS child combinator syntax.
The child combinator is more specific than the descendant (space) combinator.
Official docs: E > F selects only first-level descendants of E.
Whitespace around > is optional: div>span and div > span both work.
jQuery made > work in browsers where native CSS support was limited (e.g. old IE).
Compatibility
Browser Support
The > child combinator is standard CSS and works in jQuery 1.0+. Modern browsers support document.querySelectorAll("ul.topnav > li") natively. jQuery historically provided consistent behavior in older IE versions where CSS child selectors were not fully supported.
✓ CSS · jQuery 1.0+
jQuery Child Selector (">")
Supported in all modern browsers. Native: document.querySelectorAll("parent > child"). Direct children only — not grandchildren.
100%Standard CSS
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
> combinatorUniversal
Bottom line: Use > when nested markup could cause false matches. Prefer .children() when you already hold a jQuery collection.
Wrap Up
Conclusion
The child selector parent > child matches direct children only — a stricter, clearer alternative to the descendant combinator. The official ul.topnav > li demo shows why it matters: nested sub-menu items stay untouched while top-level items get styled.
Reach for > in menus, tables, and nested layouts. When you need every match at any depth, use a space instead — or explore jQuery traversing methods like .children() and .find().
Use .children() when starting from a jQuery object
Scope with an ID or class on the parent first
❌ Don’t
Assume ul li and ul > li are the same
Use > when you need matches at any depth
Forget that text nodes are not element children for CSS selectors
Over-chain > when a single descendant selector is clearer
Skip testing with nested markup in your Try-it examples
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about the child selector
Direct children only — not deeper descendants.
5
Core concepts
>01
Child
Direct only
Rule
ul02
Official
topnav > li
Demo
space03
Descendant
Any depth
Compare
nav04
Chain
Step by step
Pattern
.ch05
.children()
Traversal twin
API
❓ Frequently Asked Questions
The child combinator (parent > child) selects only direct children of a parent element. $("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 depth. The > combinator matches only first-level children. $("div span") finds every span inside div; $("div > span") finds spans that are immediate children of div only.
Yes. $("nav > ul > li > a") walks one level at a time — nav's direct ul, that ul's direct li children, each li's direct a children. This is clearer than a long descendant chain when you need precise depth.
Both target direct children. $("parent > child") is a CSS selector string — great for one-shot queries. .children("child") is a jQuery traversal method — useful when you already have a jQuery object and want to filter its immediate children.
Yes. The > combinator is standard CSS and works in jQuery 1.0+. jQuery also made it work in older IE versions where native CSS support was limited — one reason jQuery became popular for cross-browser DOM queries.
Use > when nested markup could cause false matches — menus with sub-menus, tables inside tables, or card grids with inner wrappers. Direct-child selection keeps your query precise and your intent obvious.
Did you know?
Before modern browsers fully supported CSS child selectors, jQuery’s selector engine let developers write $("ul > li") and get consistent results across IE6 and other legacy browsers — one reason the > combinator became a staple in jQuery tutorials.