XML DOM appendChild()Methods


Node object

Definition and Usage

The appendChild() method appends a new child node to the end of the node's list of child nodes.

This method returns the new child node.

Syntax

appendChild(newchild)

Parameter Description
newchild The node to append.


Example

The following code snippet usesloadXMLDoc()put "books.xmlLoad it into xmlDoc, create a node (<edition>), and add it after the last child node of the first <book> node:

Example

xmlDoc=loadXMLDoc("books.xml");

newel=xmlDoc.createElement("edition");

x=xmlDoc.getElementsByTagName("book")[0];
x.appendChild(newel);

document.write(x.getElementsByTagName("edition")[0].nodeName);

Output:

edition

Try it Yourself »

Try it Yourself

appendChild() - Appends a child node to all <book> nodes


Node objectother extensions