jQuery .add() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Traversing

Definition

.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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("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");
CallWhat it does
Matched setStarting collection
Selector / element / htmlExtras to merge (1.0+)
jQuery selectionMerge another set (1.1+)
selector, contextScoped search (1.4+)
Return valueNew jQuery union (must capture or chain)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select a starting set (e.g. $("div") or $("li")).
Step 2Call .add(selector), .add(element), .add(html), or .add($other).
Step 3Chain a method on the new set, or assign: set = set.add(…).

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Official: Border Divs, Then Add Paragraphs

Only early chain steps hit the original set (jQuery API demo idea).

jQuery
$("div").append(" [border]")
  .add("p")
  .append(" [bg]");
Try It Yourself

How It Works

  1. Select. Start with every div.
  2. Mark border. First .append() runs only on those divs.
  3. Add. .add("p") returns a new set with divs and paragraphs.

Example 2 — Official: $("p").add("span")

Merge two tag types, then style once.

jQuery
$("p").add("span").append(" [together]");
Try It Yourself

How It Works

  1. Start. Select all p elements.
  2. Merge. .add("span") includes every span.
  3. One action. A single .append() marks both tags.

Example 3 — Official: List Items Plus a Paragraph

Results sort in document order — list first, then the paragraph.

jQuery
$("li").add("p").append(" [red]");
Try It Yourself

How It Works

  1. Select. Start with every li.
  2. Add. Merge the following p.
  3. Order. Since 1.4, same-document sets sort as they appear on the page.

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).

Next: .addBack() Method — Restore Previous Set

Learn how to add the previous set of elements back into the chain.

.addBack() Method — Restore Previous Set tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

9 people found this page helpful