How can I remove the content of a div tag using JavaScript?
I have tried some code, but it only removes the level1
div (and of course all o it childern), but how can I remove only the content in level3
inside?
function destroyDiv() {
var div = document.getElementById("level1");
div.parentNode.removeChild(div);
}
<div id="level1">
<div id="level2">
<div id="level3">
<label> Test content </label>
</div>
</div </div>
<div id=blahDiv>Remove me</div>
<input type=button value='Remove the div' onclick='destroyDiv()'>