HTML DOM replaceChild() Method

元素对象参考手册Element Object

Example

Replace a child node with another:

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

Before removal:

  • Coffee
  • Tea
  • Milk

After removal:

  • Water
  • Tea
  • Milk

Try it Yourself »

Definition and Usage

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

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the replaceChild method


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

Other Extensions