运行 ❯
获取你
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The insertAdjacentElement() Method</h2> <button onclick="myFunction()">Move</button> <p>Click "Move" to insert the red span after the header.</p> <span id="mySpan" style="color:red">My span</span> <h2 id="myH2">My Header</h2> <script> function myFunction() { const span = document.getElementById("mySpan"); const h2 = document.getElementById("myH2"); h2.insertAdjacentElement("afterend", span); } </script> </body> </html>