You are here: Reference > JavaScript > client-side > HTML DOM > methods > cloneNode

cloneNode method

Browser support:
Returns an exact copy of the current node.
The new node contains the same attributes with the same values as the original element. The child elements of the cloned node can also be copied in the original order with the cloneNode method (depending on the first parameter of the cloneNode method). The new node has no parent, use the insertBefore or appendChild method to insert it into the document.
If you need to copy a node from another document into the current document, use the importNode method.


object.cloneNode (cloneChildren);
You can find the related objects in the Supported by objects section below.


Required in Firefox and Opera, optional in Internet Explorer, Google Chrome and Safari. Boolean that indicates whether the child element need also be duplicated.
One of the following values:
Default in Internet Explorer, Google Chrome and Safari. Do not duplicate the child elements.
Duplicate the child elements.

Return value:

Returns the newly created node.

Example HTML code 1:

This example illustrates the use of the cloneNode method:
    <script type="text/javascript">
        function Clone () {
            var srcTable = document.getElementById ("srcTable");
            var clonedTable = srcTable.cloneNode (true);
   = "";    // clear the id property of the cloned table

            var container = document.getElementById ("container");
            container.appendChild (clonedTable);
    <div id="container">
        <table id="srcTable" border="1px">
    <br /><br />
    <button onclick="Clone ();">Clone Table!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content