HTML DOM replaceChild() Method
Example
Replace a child node with another:
document.getElementById("myList").replaceChild(
newnode
,
oldnode
);
Before removing:
- Coffee
- Tea
- Milk
After removing:
- Water
- Tea
- Milk
Try it »
Definition and Usage
The replaceChild() method replaces a child node with another.
The new node can be one that already exists in the document, or one you create new.
Browser support





All major browsers support the replaceChild method
Syntax
node
.replaceChild(
newnode
,
oldnode
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| newnode | Node object | Required. The node object you want to insert. |
| oldnode | Node object | Required. The node object you want to remove. |
Return Value
| Type | Description |
|---|---|
| Node object | The replaced node |
Technical Details
| DOM version | Core Level 1 Node Object |
|---|
Element object