Copying & Moving Nodes

adoptNode() moves a node, while importNode() copies a node.


RESETRUNFULL
<!DOCTYPE html><html><body>
   <iframe src="DOM-copyB.html" onload="copy_nodes()"
                height="80" width="150"></iframe>
   <script>
      function copy_nodes(){
         var ed = document.getElementsByTagName
                                         ('iframe')[0].contentDocument;         // alternative: var ed = frames[0].document;
         var edp0 = ed.getElementsByTagName('p')[0];
         var edp1 = ed.getElementsByTagName('p')[1];
         var p0 = document.importNode(edp0,true);
         var p1 = document.adoptNode(edp1);
         document.body.appendChild(p0);
         document.body.appendChild(p1);
      }
   </script></body></html>

<!-- DOM-copyB.html --><!DOCTYPE html><html><body>
   <p>import me!</p>
   <p>adopt me!</p></body></html>