.replaceAll(target) replaces each target element with the matched set (since jQuery 1.2). Content comes first; the target is the argument — the reverse of .replaceWith().
Remember
$("<b>Paragraph.</b>").replaceAll("p")
$("<h2>New heading</h2>").replaceAll(".inner")
$(".first").replaceAll(".third") // move existing node
// same DOM result, reversed syntax:
$("p").replaceWith("<b>Paragraph.</b>")
// replaces the whole element — not just inner HTML
Build or select the replacement, pass the target(s), swap them out.
Create or select the replacement content.
Choose the target: selector, element, array, or jQuery object.
Call .replaceAll(target) — each target is swapped for the content.
Chain on the returned inserted set if you need further steps.
Piece
Required?
Role
jQuery collection
Yes
Replacement content
target
Yes
Element(s) to replace
Return
—
Inserted replacement set
Pseudocode
Pseudocode
content = matched elements (or new HTML nodes)
targets = resolve(target)
for each t in targets:
remove t (and its data/events)
if first target:
move content into t's place
else:
clone content into t's place
return inserted replacements
// Same idea as .replaceWith(), reversed syntax:
// content.replaceAll(target) ≡ target.replaceWith(content)
Reference
Cheat Sheet
Keep these facts handy while swapping elements.
Topic
Detail
Syntax
.replaceAll(target)
Since
jQuery 1.2
vs .replaceWith()
Content-first vs target-first
One target
Existing nodes move
Many targets
Clones after the first
Target cleanup
Data and events removed
vs .html()
Whole element vs inner content
Try it
Live Preview
Run official-style replaceAll actions on a tiny demo tree and see targets swap for new content.
Browser demo of .replaceAll() — same idea as the examples below.
Result
Ready — pick an action and run.
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Move, not clone. Hello leaves its old spot and fills third’s place.
Official rule. Single location → move.
Example 4 — replaceAll vs replaceWith
Same swap; pick content-first or target-first syntax.
jQuery
// Content first
$("<strong>Done</strong>").replaceAll("#status");
// Target first — same DOM result
$("#status").replaceWith("<strong>Done</strong>");
Prefer .text() for user strings when building replacement nodes.
Compatibility
Browser Support
.replaceAll() is a core jQuery method (since 1.2). It needs a browser DOM with jQuery loaded.
✓ jQuery 1.2+ · Browsers only
jQuery .replaceAll()
Works in Chrome, Firefox, Safari, Edge, and other browsers with jQuery. Not for Node.js without a DOM.
100%Browser support
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
.replaceAll()Browsers
Bottom line: Use .replaceAll(target) in the browser for content-first element swaps. Prefer .replaceWith() when the target is already selected.
Analysis
Performance Notes
Approach
Cost
Best for
.replaceAll(one)
Low
Single element swap / move
.replaceAll(many)
Higher
Clones per extra target
.html()
Often lower
Updating inside a kept shell
Prefer one clear replace over many tiny swaps in a loop. If you only need new inner content, .html() is usually cheaper.
Remember
Key Takeaways
Role: replace each target with the matched content.
Syntax: content first — mirror of .replaceWith().
Move vs clone: one target moves; many targets clone.
Not html: the whole element is swapped, not just its insides.
One line:$(content).replaceAll(target) swaps targets for content — content-first twin of .replaceWith().
Frequently Asked Questions
.replaceAll(target) replaces each target element with the elements in the current jQuery collection. Content comes first in the syntax. Returns the inserted replacements. Available since jQuery 1.2.
Same DOM result, reversed syntax. Target first: $('p').replaceWith('<b>Hi</b>'). Content first: $('<b>Hi</b>').replaceAll('p'). Prefer replaceAll when you build the replacement first.
One target location: existing replacement nodes move (not clone). Multiple targets: clones for every target after the first.
Data and event handlers on the removed target nodes are cleaned up. The replacement elements keep their own handlers.
A CSS selector, jQuery object, DOM element, or array of elements identifying what to replace.
.html() changes what is inside an element; the outer tag stays. .replaceAll() removes the entire target and puts the replacement in its place.