Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Cloning Nodes with Children</title> </head> <body> <div id="original"> Original Node <span>Child Node</span> </div> <button id="clone">Clone Node with Children</button> <script> document.getElementById('clone').addEventListener('click', () => { const original = document.getElementById('original'); const clone = original.cloneNode(true); // Clone with children clone.id = 'clone'; document.body.appendChild(clone); }); </script> </body> </html>