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

XML DOM removeChild() Method


Node Object Reference Node Object

Definition and Usage

The removeChild() method removes a specified child node from the current node.

Tip: The removed child node can be inserted later into any element in the same document. Use the insertBefore() or appendChild() method to insert it later into the same document, or use the adoptNode() or importNode() method to insert the removed node into another document.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

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


Syntax

nodeObject.removeChild(child)

Parameters

Parameter Type Description
child Node object Required. The node to remove

Return Value

Type Description
Node object Returns the removed node as a Node object

Technical Details

DOM Version Core Level 1 Node Object. Modified in DOM Level 3


Example

The following code fragment loads "books.xml" into xmlDoc using loadXMLDoc() and removes the first child node in the first <book> node:

Example

xmlDoc = loadXMLDoc("books.xml");

root = xmlDoc.documentElement;
currNode = root.childNodes[1];
removedNode = currNode.removeChild(currNode.childNodes[1]);
document.write("Removed node: " + removedNode.nodeName);

Output:

Removed node: title

Try it yourself »

Node Object Reference Node Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook