+ 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
2 ответов
+ 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...)
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