This scenario involves the task of eliminating all paragraphs. Despite using a for-loop, not all paragraphs were successfully removed. The initial paragraph remained unaltered. http://codepen.io/vinhnghi223/pen/jnkzh
article=document.getElementsByTagName("article")[0];
for (i=0; i<article.childNodes.length; i++) {
article.removeChild(article.lastChild);
}
On the contrary, modifying the code to use i<4 (which is less than article.childNodes.length
, resulting in 5) solves the issue.
The perplexity arises from the fact that article.childNodes.length
returns 5. Although it seems logical that if it works with 4 items, it should work with 5 as well.