According to this: https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild
If I want to eliminate all children, I have to do something like this:
Using that approach –
<table id="rankings-table">
<thead>
<tr>
<th>Ranking</th>
<th>Full Name</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Steven</td>
<td>2019</td>
</tr>
<tr>
<td>2</td>
<td>John</td>
<td>2001</td>
</tr>
</tbody>
</table>
// Javascript
const rankingsBody = document.querySelector("#rankings-table > tbody");
const rows = rankingsBody.firstChild;
// Clears out existing data
while (rows) {
console.log(rankingsBody.removeChild(rows));
}
console.log(json);
How come it does not remove all children when storing the firstChild as a variable, rows? Can someone explain friendly and thoroughly?
What does while(rows) exactly mean here? If “rows” never changes, shouldn’t loop the break once the first child is no longer a “textNode”? How come
while (rows) {
console.log(rankingsBody.removeChild(rankingsBody.firstChild));
}
this works tho?