0
Q:

Javascript remove all child elements

function deleteChild() { 
        let e = document.querySelector("ul"); 
        
        //e.firstElementChild can be used. 
        let child = e.lastElementChild;  
        while (child) { 
            e.removeChild(child); 
            child = e.lastElementChild; 
        } 
    } 
    let btn = document.getElementById( 
    "btn").onclick = function() { 
        deleteChild(); 
    } 
1
var myDiv = document.getElementById("myDivID");
    myDiv.innerHTML = "";//remove all child elements inside of myDiv
3
document.getElementById("myId").innerHTML = '';
1

New to Communities?

Join the community