100
rated 0 times
[
107]
[
7]
/ answers: 1 / hits: 64430
/ 13 Years ago, fri, may 6, 2011, 12:00:00
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()'>
More From » javascript