Search w3schools.com:

SHARE THIS PAGE

DOM Node replaceChild() Method

Node Object Reference Node Object

Example

Replace an item in a list with a new item:

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

Before removing:

  • Coffee
  • Tea
  • Milk

After removing:

  • Water
  • Tea
  • Milk

Try it yourself »

Definition and Usage

The replaceChild() method replaces a child node with a new node.

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


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The replaceChild() method is supported in all major browsers.


Syntax

node.replaceChild(newnode,oldnode)

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 Reference Node Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]