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

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

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

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 20:56

        var p=document.getElementById('childId').parentNode;
        var c=document.getElementById('childId');
        p.removeChild(c);
        alert('Deleted');
    

    p is parent node and c is child node
    parentNode is a JavaScript variable which contains parent reference

    Easy to understand

提交回复
热议问题