I found some jQuery code to clear the contents of a div:
$('#masterdiv').empty();
Is there any similar way to do this in raw javascript, without jQuery or any other library?
I found some jQuery code to clear the contents of a div:
$('#masterdiv').empty();
Is there any similar way to do this in raw javascript, without jQuery or any other library?
This code will work.
while (myNode.firstChild) {
myNode.removeChild(myNode.firstChild);
}
Mention the id of the tag on myNode for which you want to remove the inner child.
myNode.lastChild instead of myNode.firstChild is usually faster.lastChild. Imagine a stack of coins: firstChild is at the bottom, lastChild is at the top. It is easier to remove the top coin than the bottom one. measurethat.net/Benchmarks/Show/3545/0/…Please have a look on http://jsfiddle.net/2dJAN/19/
<div class="btn-post">123</div>
$(".btn-post").html("")