\n\n
\n

The cloneNode() method creates a copy of a node.

\n

This method returns the cloned node.

\n
\n\n

Browser Support

\n\n\n\n\n\n\n\n\n\n
MethodInternet ExplorerFirefoxOperaGoogle ChromeSafari
cloneNode()1.0
\n\n

Syntax

\n
node.cloneNode(deep)
\n\n\n\n\n\n\n\n\n\n
ParameterDescription
deep\n

Optional, Boolean.

\n
    \n
  • true indicates that the node's children will also be cloned.
  • \n
  • false indicates that only the node itself will be cloned.
  • \n
\n
\n\n

Technical Details

\n\n\n\n\n\n\n\n\n\n
Return Value:A Node object representing the cloned node.
DOM VersionCore Level 1 Node Object
\n\n

More Examples

\n

Example

\n

Copy the child nodes of a list item:

\n
\n

Example

\n

Copy a list item and all its child nodes:

\n
\n
<ul id="myList1"><li>Coffee</li><li>Tea</li></ul>\n<ul id="myList2"></ul>\n\n<script>\nvar itm = document.getElementById("myList2").lastChild;\nvar cln = itm.cloneNode(true);\ndocument.getElementById("myList2").appendChild(cln);\n</script>
\n
\n

Try it Yourself »

\n
\n
\n

Example

\n

Copy a list item without its child nodes:

\n
\n
<ul id="myList1"><li>Coffee</li><li>Tea</li></ul>\n<ul id="myList2"></ul>\n\n<script>\nvar itm = document.getElementById("myList2").lastChild;\nvar cln = itm.cloneNode(false);\ndocument.getElementById("myList2").appendChild(cln);\n</script>
\n
\n

Try it Yourself »

\n
\n\n