DOM Element.replaceWith() Method
The replaceWith() method replaces an element in the page with other nodes or text.
Description
The replaceWith() method replaces the element with the given nodes or strings, in its parent's list of children. Strings are inserted as text.
If the element has no parent, the call does nothing. Like other insertion methods, nodes passed to it are moved if they're already in the page, and you can pass several nodes and strings to replace one element with many.
A common use is swapping a placeholder, such as a loading message or skeleton, for real content once data arrives. The element's own event listeners don't transfer to its replacement.
Syntax
element.replaceWith(param1, param2, ...)Parameters
- param1, param2, ...Nodes or strings to put in place of the element.
Return Value
None (undefined).
Example
Browser Support
The following information will show you the current browser support for the Element.replaceWith() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





