Latest web development tutorials

XML DOM appendChild () method

Node Object Reference Node objects

Definition and Usage

appendChild () method to add a new child node to the end of the list of child nodes of the node.

This method returns the new child node.

grammar

appendChild(newchild)

参数 描述
newchild 要追加的节点。


Examples

The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc create nodes (<edition>), and add it to the first <book> node behind last child node:

Examples

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 Demos

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


Node Object Reference Node objects