ryoakg
6/3/2016 - 1:55 PM

js-clone-node.html

<html>
  <head>
    <style>
     .box{
       width: 200px;
       height: 200px;
     }
    </style>
  </head>
  <body>
    <div id="tmpl" class="box" style="display:none">
      <ul>
        <li>a</li>
        <li>b</li>
        <li>c</li>
        <li>d</li>
      </ul>
    </div>
    <script>
     var tmpl = document.getElementById('tmpl');
     var body = document.getElementsByTagName('body')[0];
     ['#eed', '#ede', '#dee'].forEach(function(c){
       var e = tmpl.cloneNode(true);
       e.style.backgroundColor = c;
       e.style.display = 'block';
       e.removeAttribute('id');
       body.appendChild(e);
       console.log(c);
     })
    </script>
  </body>
</html>