Clone DOM node - Javascript DOM

Javascript examples for DOM:Element cloneNode

Description

Clone DOM node

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <div id="main"> 
         <button id="mybtn">click me for index </button> 
      </div> 
      <script>
var myarray = [2,4,6,5,5];/*from w  w w. jav  a 2 s  .c om*/
for(var i=0; i<= myarray.length; i++){
  var allBtn = document.getElementById("mybtn").cloneNode(true);
  document.body.appendChild(allBtn);
}

      </script>  
   </body>
</html>

Related Tutorials