HTML DOM cloneNode() method
Example
Copy a list item to another list:
var node=document.getElementById("myList2").lastChild.cloneNode(true);
document.getElementById("myList1").appendChild(node);
Before copying:
-
Coffee
-
Tea
-
Water
-
Milk
After copying:
-
Coffee
-
Tea
-
Milk
-
Water
-
Milk
Try it »
Definition and Usage
The cloneNode() method creates an exact copy of the specified node.
The cloneNode() method copies all attributes and values.
This method copies and returns a duplicate of the node that invoked it. If the argument passed to it is true, it will also recursively copy all descendant nodes of the current node. Otherwise, it only copies the current node.
Browser support





All major browsers support the cloneNode() method
Syntax
node
.cloneNode(
deep
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| deep | Boolean | Optional. This method copies and returns a duplicate of the node that invoked it. If the argument passed to it is true, it will also recursively copy all descendant nodes of the current node. Otherwise, it only copies the current node. |
Return Value
| Type | Description |
|---|---|
| Node object | The copied node |
Technical Details
| DOM version | Core Level 1 Node Object |
|---|
Element object