What is the correct way to remove the content of an element <div id="root"></div>
of HTML 5 if this element contains other elements <div></div>
, I have tried these two options and both work, but I would like to know which is correct or the difference between using one or the other.
First form:
var div = document.getElementById('root');
while (div.firstChild) {
div.removeChild(div.firstChild);
}
Second form:
document.getElementById('root').innerHTML = '';