Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM replaceChild method

HTML DOM replaceChild() Method

Element Object Reference Element object

Example

Replace a child node with another:

document.getElementById("myList").replaceChild(

newnode

,

oldnode

);

Before removing:

After removing:

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 Reference Element object