JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test">Hey!
<div id="child">delete me</div>
</div>
JavaScript
var b = document.getElementById("test");
console.log("b before:", b);
while(b.firstChild) {
console.log("removing child:",b.firstChild);
b.removeChild(b.firstChild);
}
console.log("b's value post remove:", b);
b.appendChild(document.createTextNode("Some new text."));
var text = b.textContent || b.innerText;
console.log("text:", text);