A jQuery selection is a collection of DOM elements, not a single node. Traversing methods let you grow, shrink, or navigate those collections before you style or manipulate them. Start with .add() to union sets — this hub links to 32 traversing method tutorials (more coming soon).
01
Collections
Matched sets
02
.add()
Union sets
03
Selectors
Match more
04
Chaining
Stack & .end()
05
Deduped
Unique nodes
06
32 guides
Full index
Fundamentals
Introduction
When you write $("li.active"), jQuery stores every matching list item in an internal array-like object. Often you need to include more elements — siblings, headings, footer links — without running a second query and merging results yourself.
What Is jQuery Traversing?
Traversing covers methods that operate on jQuery collections: combining sets with .add(), filtering with .not(), walking the tree with .parent() and .find(), and returning to earlier selections with .end(). These methods answer “which elements am I working with?” — not “how do I change the HTML?”
💡
Beginner Tip
Think of a jQuery object as a basket of DOM nodes. .add() puts more items in the basket; .not() removes some; .end() swaps back to the basket you had before the last filter.
Key Features
Non-destructive — Traversing returns new jQuery objects; earlier selections stay on the internal stack.
Flexible arguments — .add() accepts selectors, DOM nodes, HTML strings, or other jQuery objects.
Automatic deduplication — The same element never appears twice in one collection.
Chain-friendly — Combine traversing with manipulation: $("h2").add("p").css("color", "navy").
Foundation
📝 Syntax
Minimal .add() workflow:
jQuery
// Start with list items, add every paragraph
const $combined = $("li").add("p");
$combined.addClass("highlight");
Method groups
Group
Examples
Purpose
Collection building
.add()
Union the current set with more matched elements
Filtering
.not(), .filter()
Remove or keep elements in the current set
Tree walking
.parent(), .children(), .find()
Move to related nodes in the DOM
Stack navigation
.end()
Return to the previous jQuery object on the chain stack
This hub currently documents .add() in depth. Additional traversing tutorials will appear in the index as they are published.
Cheat Sheet
⚡ Quick Reference
Goal
Method
Add elements by selector
$("li").add("p")
Add a DOM element
$("li").add(document.getElementById("footer"))
Add parsed HTML
$("li").add("<span class='badge'>new</span>")
Union two jQuery objects
$("h2").add($("h3"))
Scope selector to a context
$("li").add("p", "#sidebar")
Undo last filter (stack)
$("div").find("p").end() → back to div
Context
When to Use Traversing
Batch styling — Highlight headings and paragraphs together with one .add() chain.
Form validation — Collect inputs, labels, and error messages into one set before toggling classes.
Event handlers — Attach one listener to multiple unrelated element groups.
Avoid duplicate queries — Merge selections instead of looping two separate jQuery objects.
Progressive tutorials — Learn collection building with .add() before filters and tree walkers.
Preview
👀 .add() vs .addBack() vs .end()
Four traversing ideas beginners often mix up — all work on collections, not DOM insertion:
.add() → union current set + matched elements → grows with new selector/DOM input .addBack() → union current set + previous stack set → merges after .find(), .nextAll(), etc. .end() → return previous stack set only → discards current selection .not() → remove matching elements from set → shrinks the collection Example: $("li.third-item").nextAll().addBack() // item 3 + following siblings Example: $("li").add("p") // all li PLUS all p $("div").find("p").addBack() // div AND its p children $("div").find("span").end() // back to $("div") only
Traversing Method Tutorial Index
Search by method name or browse by category. Each tutorial includes syntax, try-it examples, and FAQs.
Collection Building
1 tutorial
Expand the current matched set by combining additional elements.
Get all siblings of each element in the current set — every element at the same parent level except the element itself, optionally filtered by a selector.
Narrow or test a matched collection — boolean checks, first or last element, descendant containment, by index, even or odd positions, selector, or callback tests.
Remove elements from the matched set — keep elements that do not match a selector, fail a callback test, or match a provided DOM element or jQuery object.
Count: (number of li + p elements on page)
(outline applied to every li and p)
How It Works
.add("p") searches the document for paragraphs and merges them with the existing li set. The result is a new jQuery object — the original $("li") is unchanged.
Example 2 — Add a DOM Element Directly
Pass a raw DOM node when you already have a reference from vanilla JavaScript.
Sidebar links included: (nav a count + sidebar a count)
How It Works
Without context, .add("a") would match every anchor on the page. The second argument restricts the search to #sidebar only.
Pro Tips
💡 Best Practices
✅ Do
Use .add() to batch actions on unrelated groups
Pass a context when the selector would otherwise be too broad
Chain .add() before one .css() or .on() call
Store merged collections in a variable for reuse
Use .end() to return after .find() or .filter()
❌ Don’t
Confuse .add() with .append() or .after()
Expect .add() to insert HTML into the document tree
Re-query the DOM when you can union existing jQuery objects
Forget that results are deduplicated — order may differ from input
Skip the method tutorial when you need edge-case syntax
Summary
Key Takeaways
Knowledge Unlocked
Four things to remember about Traversing
Your starting point for 32 method tutorials.
4
Core concepts
+01
.add()
Union sets
Start
−02
.not()
Filter out
Shrink
↩03
.end()
Go back
Stack
3204
Index
Search all
Ref
❓ Frequently Asked Questions
Traversing methods work on jQuery collections — they move between elements, filter sets, or combine matched nodes without inserting HTML into the DOM. .add() is a collection-building method that unions the current set with more elements.
.add(selector) returns a new jQuery object containing every element in the current set plus any elements matched by the argument. You can pass a CSS selector, DOM element, HTML string, or another jQuery object.
.add() combines two groups of elements into one jQuery collection for further chaining — it does not insert nodes into the DOM. .append() is a manipulation method that inserts content as a child of matched elements.
No. Like most jQuery methods, .add() returns a new jQuery object. The previous selection remains available — use .end() after a chain of filters to pop back to an earlier set on the internal stack.
Yes. $("li").add($("p")) unions both collections. jQuery deduplicates elements so the same node is not listed twice in the result.
Read the overview, study the add vs not vs end comparison, try the hub examples, then open the .add() tutorial for full syntax, five try-it labs, and method-specific FAQs.
Did you know?
jQuery keeps an internal stack of collections as you chain traversing methods. After $("div").find("p").add("span"), calling .end() twice walks back through find and returns you to the original $("div") set.
Wrap Up
🎉 Conclusion
jQuery Traversing helps you shape which elements you operate on before changing content or styles. Start with .add() to union collections, keep .not() and .end() in mind for filtering and stack navigation, and use the searchable index as more method tutorials go live.
Open the .add() tutorial next for full syntax, interactive labs, and method-specific FAQs.