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

HTML DOM cloneNode method

HTML DOM cloneNode() method

Element Object Reference Element object

Example

Copy a list item to another list:

var node=document.getElementById("myList2").lastChild.cloneNode(true);

document.getElementById("myList1").appendChild(node);

Before copying:

After copying:

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 Reference Element object