cloneNode

You can use the cloneNode method to duplicate existing elements.

 
<!DOCTYPE HTML> 
<html> 
    <head> 
        <title>Example</title> 
    </head> 
    <body> 
        <table border="1"> 
            <tbody id="SurveysBody"> 
                <tr><td class="sum">A</td><td class="result">B</td></tr> 
            </tbody> 
        </table> 
        <button id="add">Add Row</button> 
        <script> 
            var tableBody = document.getElementById("SurveysBody"); 
            document.getElementById("add").onclick = function() { 
                var count = tableBody.getElementsByTagName("tr").length + 1; 
                var newElem = tableBody.getElementsByTagName("tr")[0].cloneNode(true); 
                newElem.getElementsByClassName("sum")[0].firstChild.data = count + " + " + count; 
                newElem.getElementsByClassName("result")[0].firstChild.data = count * count; 
                tableBody.appendChild(newElem); 
            }; 
        </script> 
    </body> 
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    DOM  

HTMLElement:
  1. The HTMLElement Members
  2. element tag name, id, direction, language, hidden disabled information
  3. addEventListener
  4. appendChild
  5. attributes returns a collection containing all of the attributes
  6. classList
  7. className
  8. cloneNode
  9. createElement
  10. createTextNode
  11. dataset
  12. getAttribute
  13. getElementsByTagName
  14. hasAttribute
  15. innerHTML
  16. insertAdjacentHTML
  17. insertBefore
  18. isSameNode
  19. outerHTML
  20. onmouseout
  21. onmouseover
  22. querySelectorAll
  23. removeEventListener