HTML | DOM replaceChild() Method
The replaceChild() method in HTML DOM is used to replace a child node with a new node within the given parent node.
parentNode.replaceChild( newChild, oldChild )
Parameter Values: This method accept two parameters which are listed below:
- newChild: It is the required parameter. It represents the new node which need to be inserted.
- oldChild: It is the required parameter. It represents the node which is replaced by new node.
Return Value: It returns a node object which represents the replaced node.
Example: In this example the first <li> text is replaced with the new text.
Before click on the button:
After click on the button:
Supported Browsers: The browser supported by DOM replaceChild() method method are listed below:
- Google Chrome 1
- Edge 12
- Internet Explorer 6
- Firefox 1
- Opera 7
- Safari 1.1