+ 4

[SOLVED] Avoiding undefined childNodes

Can I know how to avoid undefined childNodes? https://code.sololearn.com/W5Xp79DKiKH4/?ref=app

12th Dec 2018, 12:52 PM
Gordon
Gordon - avatar
2 Réponses
+ 6
childNode would include textNode and comment, use children instead. https://code.sololearn.com/WuSlnqPIv3qD/?ref=app
12th Dec 2018, 1:10 PM
Calviղ
Calviղ - avatar
+ 4
You can follow what Calviղ told. His approach is best Or you can do as follow : //code snippet for (var i=0;i<document.getElementById("myDIV").children.length;i++) { if(typeof(document.getElementById("myDIV").children[i] != undefined)) { //your code here } }
12th Dec 2018, 1:29 PM
Rishi Anand
Rishi Anand - avatar