Easy Tutorial
❮ Event Onplaying Prop Element Previouselementsibling ❯

HTML DOM replaceChild() Method

Element Object

Example

Replace one child node with another:

document.getElementById("myList").replaceChild(newnode, oldnode);

Before removal:

Coffee
Tea
Milk

After removal:

Water
Tea
Milk

Definition and Usage

The replaceChild() method replaces a child node with another one.

The new node can be an existing node in the document, or you can create a new one.


Browser Support

All major browsers support the replaceChild method.


Syntax

Parameters

Parameter 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

❮ Event Onplaying Prop Element Previouselementsibling ❯