Element.replaceChildren() is an instance method from the ParentNode API. It replaces all existing children with a new set of nodes or strings. Learn how to empty a container, transfer nodes between lists (MDN party food demo), how it compares to append() and innerHTML, and five try-it labs.
01
Kind
Instance method
02
Action
Replace all kids
03
Args
Nodes or strings
04
Empty
No arguments
05
vs append
Adds only
06
Status
Baseline widely
Fundamentals
Introduction
Old patterns clear children with loops or innerHTML = "". replaceChildren() is the modern ParentNode helper: swap the entire child list in one call—or empty the element by calling it with no arguments (MDN).
Like append() and prepend(), strings become Text nodes automatically.
💡
Beginner tip
MDN: myNode.replaceChildren() with no args is a convenient way to empty a node of all its children—cleaner than manual loops.
param1, …, paramN (optional) — a set of Node objects or strings to replace the element’s existing children with (MDN). If omitted, all children are removed.
Return value
None (undefined) (MDN).
Exceptions
Thrown when the constraints of the node tree are violated (MDN).
Common patterns
JavaScript
// Empty all children (MDN)
myNode.replaceChildren();
// Replace with new content
container.replaceChildren(heading, paragraph, " ");
// Transfer nodes between parents (MDN party food pattern)
yesSelect.replaceChildren(...selected, ...existing);
Cheat Sheet
⚡ Quick Reference
Goal
Code
Empty all children
el.replaceChildren()
Replace with nodes
el.replaceChildren(a, b)
Replace with text
el.replaceChildren("Hello")
Transfer nodes
el.replaceChildren(...nodes)
Return value
undefined
MDN status
Baseline Widely available (since October 2020)
Snapshot
🔍 At a Glance
Four facts to remember about Element.replaceChildren().
Returns
undefined
Updates the DOM in place
Baseline
widely
Since Oct 2020
Empty
()
No arguments
Strings
→ Text
Auto Text nodes
Compare
📋 replaceChildren() vs append() vs innerHTML
replaceChildren()
append()
innerHTML = ""
Existing children
Removed first
Kept
Replaced (parsed HTML)
Accepts strings?
Yes (as Text)
Yes (as Text)
HTML string only
Empty container
replaceChildren()
No effect alone
innerHTML = ""
Return value
undefined
undefined
String assigned
Best for
Swap all children
Add at end
HTML string templates
MDN highlights replaceChildren() for emptying nodes and transferring children between parents without verbose loop code.
Element.replaceChildren() is Baseline Widely available (MDN: across browsers since October 2020). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.replaceChildren()
Replace all child nodes at once — empty with no args, or pass nodes and strings.
BaselineWidely available
Google ChromeSupported · Desktop & Mobile
Yes
Microsoft EdgeSupported · Chromium
Yes
Mozilla FirefoxSupported · Desktop & Mobile
Yes
Apple SafariSupported · macOS & iOS
Yes
OperaSupported · Modern versions
Yes
Internet ExplorerNot supported
No
replaceChildren()Excellent
Bottom line: Use replaceChildren() to empty containers or swap entire child lists. Use append() when you only need to add at the end.
Wrap Up
Conclusion
Element.replaceChildren() is the modern way to swap an element’s entire child list—or empty it with no arguments. It returns undefined and updates the DOM in place.
Confuse with replaceWith() (replaces the element itself)
Forget removed children are detached from the parent
Assume IE supports replaceChildren()
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.replaceChildren()
Replace all children in one call.
5
Core concepts
📝01
Empty
no args
Clear
📄02
Args
nodes + text
Flexible
✍️03
Transfer
spread ...
MDN
⚡04
vs append
clears first
Compare
✅05
Baseline
since 2020
Status
❓ Frequently Asked Questions
It replaces the existing children of an element with a new set of child nodes or strings (MDN). If no arguments are passed, the element is emptied of all child nodes.
No. MDN marks Element.replaceChildren() as Baseline Widely available (across browsers since October 2020). It is not Deprecated, Experimental, or Non-standard.
Call replaceChildren() with no arguments: el.replaceChildren(). MDN describes this as a convenient way to remove all children.
Zero or more Node objects or strings. Strings are inserted as equivalent Text nodes, like append() and prepend() (MDN).
Nothing useful — the return value is undefined (MDN).
append() adds after the last child. replaceChildren() removes all existing children first, then inserts the new set.
Did you know?
MDN’s party food demo shows how replaceChildren(...selected, ...existing) transfers <option> nodes between two <select> lists in one call—no manual loop required.