X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM replaceChild() Method

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


Element Object Reference Element Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook