1. 获取到当前节点.

2. 获取到当前节点的父节点.

3. 使用 Node.prototype.removeChild() 移除当前节点.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <p id="id1">Hello, World!</p>
    <script>
        // var id1 = document.getElementById("id1");
        // if (id1.parentNode) {
        //     id1.parentNode.removeChild(id1);
        // }
    </script>
</body>
</html>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案