Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM appendChild() Method

XML DOM appendChild() Method


Node Object Reference 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)

Parameters Description
newchild The node to append.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc, create a node ( ), and add it to the first node after its last child 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 »


Try it

appendChild() - Append a child node to all nodes


Node Object Reference Node object