运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The cloneNode() Method</h2> <button onclick="myFunction()">Copy</button> <p>Click "Copy" to copy the "demo" element, including all its attributes and child elements, and append it to the document.</p> <div id="demo" style="border:1px solid black;background-color:pink"> <p style="color:red;">A p element</p> <p style="color:green;">A p element</p> <p style="color:blue;">A p element</p> </div> <script> function myFunction() { const node = document.getElementById("demo"); const clone = node.cloneNode(true); document.body.appendChild(clone); } </script> </body> </html>