.add() (since jQuery 1.0) builds a new jQuery object from the union of the current matched elements and extras you pass in — selector, DOM node(s), HTML string, or another jQuery object (1.1+). It does not insert nodes into the page.
Remember
$("p").add("div") // union of p + div
$("li").add("p") // list items + paragraph
$("p").add(document.getElementById("a"))
$("p").add("<b>hi</b>") // HTML in memory only
// Wrong — original unchanged:
// pdiv.add("div");
// Right:
// pdiv = pdiv.add("div");
Start with a set, merge extras, then style or act on the combined collection.
Select a starting set (e.g. $("div") or $("li")).
Call .add(selector), .add(element), .add(html), or .add($other).
Chain a method on the new set, or assign: set = set.add(…).
Remember: since 1.4, same-document results are in document order.
To put HTML from .add() on the page, chain an insertion method.
Piece
Required?
Role
Matched set
Yes
Starting collection
Selector / element / html
One form
Extras to merge (1.0+)
jQuery selection
One form
Merge another set (1.1+)
selector, context
Optional
Scoped search (1.4+)
Return value
—
New jQuery union (must capture or chain)
Pseudocode
Pseudocode
call $(set).add(extra)
result = copy of set
extraElements = resolve(extra) // selector / node / html / jQuery
for each e in extraElements:
if e not already in result:
result.add(e)
if all elements share one document:
sort result in document order // since jQuery 1.4
return result as a NEW jQuery object
// original set is unchanged
Reference
Cheat Sheet
Keep union vs insert vs exclude clear.
Topic
Detail
Syntax
.add(sel|el|html|jQuery[, ctx])
Since
1.0 · jQuery object 1.1 · context 1.4
Order
Document order (same document, 1.4+)
Mutates original?
No — reassign or chain
vs .append()
Collection vs DOM insert
vs .not()
Union vs exclude
Reverse
.not() or .end()
Try it
Live Preview
Merge different node types, then list the combined set in document order.
Box A
Box B
A paragraph
A span
Official idea: .add() unions sets; same-document results sort in document order.
Result
Ready — choose a call and click Run.
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.
Example 1 — Official: Border Divs, Then Add Paragraphs
Only early chain steps hit the original set (jQuery API demo idea).
Hello [yes]
Hello Again [yes]
(Without reassignment, #a would stay unmarked)
How It Works
Store.collection starts as only paragraphs.
Wrong call. Calling .add() without using the return value does nothing useful.
Reassign. Save the new union back into collection.
Act. Now .append() hits paragraphs and the extra node.
Edge Cases & Pitfalls
Common mistakes when growing a jQuery set.
reassign
Forgotten return value
Official warning: pdiv.add("div") alone leaves pdiv unchanged. Chain or reassign.
html
HTML is in memory only
.add("<p>hi</p>") creates nodes but does not show them. Append with .append() / .appendTo().
order
Document order, not arg order
Since 1.4, same-document unions sort by page position. Cross-document order is undefined.
vs append
.add() ≠ .append()
One grows the collection; the other inserts into the DOM. Do not mix the names up.
Compatibility
Browser Support
.add() has been part of jQuery since 1.0. jQuery-object arguments arrived in 1.1; selector + context and document-order sorting in 1.4. It works in every browser that runs your loaded jQuery version.
✓ Stable · jQuery 1.0+
jQuery .add()
Supported across jQuery 1.x, 2.x, and 3.x. Prefer a current jQuery 3.x build. Always capture or chain the returned set.
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
.add()Universal
Bottom line: Safe for merging selectors, DOM nodes, and jQuery objects. Remember: new set, document order since 1.4, HTML needs an insert step.
Analysis
Performance Notes
Approach
Cost
Best for
.add(element)
Cheapest
Known DOM node already in hand
.add(selector)
OK
Small, scoped pages
.add(sel, context)
Better
Limit the search root (1.4+)
One multi-selector
Often enough
$("p, span") when both are known upfront
Prefer a single combined selector when you know both sets ahead of time. Use .add() when sets arrive in steps or from different sources.
Remember
Key Takeaways
Role: build a new union of matched elements.
Capture: reassign or chain — never call and discard.
One line:.add() grows the collection, not the DOM — assign the result, then style or insert.
Frequently Asked Questions
.add() creates a new jQuery object that is the union of the current matched elements plus extra elements you pass in — a selector, DOM element(s), HTML snippet, or another jQuery object. Available since jQuery 1.0.
No. Official docs: .add() returns a new set and leaves the original unchanged. Capture it: collection = collection.add(el); or chain directly.
.add() only builds a larger jQuery collection in memory. .append() inserts nodes into the DOM. HTML passed to .add() will not appear on the page until you use an insertion method.
Since jQuery 1.4, when all elements are in the same document, .add() sorts them in document order — not necessarily the order you passed arguments.
Use .not(selector|elements) to drop items from the combined set, or .end() to return to the selection before .add() in a chain.
Anything $() accepts: a selector (1.0), DOM element(s) (1.0), HTML string (1.0), a jQuery object (1.1), or selector plus context (1.4).