Skip to content
html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #box01 {
      width: 100px;
      height: 100px;
      background: pink;
    }

    #box01 span {
      color: red;
    }
  </style>
</head>
<body>
  <!-- 
    cloneNode(true/false):克隆元素
    removeChild:移除元素 容器.removeChild(元素)
   -->
   
   <div id="box01">
     <span>Foo</span>
   </div>

   <script>
    const box01 = document.querySelector('#box01')
    const box02 = box01.cloneNode(true) // 深克隆
    const box03 = box01.cloneNode(false) // 浅克隆,没有克隆到span

    document.body.appendChild(box02)
    document.body.appendChild(box03)

    box03.innerHTML = '<span>Hello</span>'

    // 移除
    // box03.parentNode.removeChild(box03)
    // document.body.removeChild(box02)
  </script>
</body>
</html>