How can I remove a child node in HTML using JavaScript?

前端 未结 9 1425
野的像风
野的像风 2020-12-12 20:22

Is there a function like document.getElementById(\"FirstDiv\").clear()?

9条回答
  •  自闭症患者
    2020-12-12 20:57

    If you want to clear the div and remove all child nodes, you could put:

    var mydiv = document.getElementById('FirstDiv');
    while(mydiv.firstChild) {
      mydiv.removeChild(mydiv.firstChild);
    }
    

提交回复
热议问题