Easy Tutorial
❮ Prop Attr Baseuri Dom Nodes Set ❯

XML DOM cloneNode() Method


Definition and Usage

The cloneNode() method creates an exact copy of the specified node.

This method returns the cloned node.

Syntax

Parameter Description
include_all Required. If the boolean parameter is set to true, the cloned node will clone all child nodes of the original node.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc, clones the first <book> node, and appends it to the end of the node list:

Example

xmlDoc = loadXMLDoc("books.xml");
x = xmlDoc.getElementsByTagName('book')[0];
cloneNode = x.cloneNode(true);
xmlDoc.documentElement.appendChild(cloneNode);

// Output all title node text values
y = xmlDoc.getElementsByTagName("title");
for (i = 0; i < y.length; i++) {
  document.write(y[i].childNodes[0].nodeValue);
  document.write("<br>");
}

Output:

❮ Prop Attr Baseuri Dom Nodes Set ❯