Document.getElementByID and for loop - Javascript DOM

Javascript examples for DOM:Document getElementById

Description

Document.getElementByID and for loop

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];//  ww w  .j av  a  2 s .  co  m
for(var i=0; i<= myarray.length; i++){
  var allBtn = document.getElementById("mybtn").cloneNode(true);
  document.body.appendChild(allBtn);
}

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

Related Tutorials