+ 9

Why there are seven nodes in a tree paragraphs div?

I have 3 paragraphs in my code. I change the text in those paragraphs to new text and numbers with JS. However I get numbers 1, 3 and 5. Also there are 7 elements in the selected elements array. Why? https://code.sololearn.com/W2J4vmmF4UgX/?ref=app

13th Feb 2021, 1:52 AM
Dual Core
Dual Core - avatar
2 Respostas
+ 2
use element.children rather than element.childNodes... first return only elements (tags), while second return all nodes (tags but also text, comments and so on...)
13th Feb 2021, 2:03 AM
visph
visph - avatar
0
Goodnight. You get an error at the end because you don't call the function: (d.hasChildNodes) You can find out by: console.log(d.hasChildNodes)/*Recturn function;*/ but if you call it like this: console.log(d.hasChildNodes());/*if the element exists: return true; else return false*/ if the object exists it returns true. otherwise false
13th Feb 2021, 4:34 AM
Daniel Briceño
Daniel Briceño - avatar