0

Why is this code not working

Im trying to get the first child node of the div element and change its contents but my code is not working. Please have a look and tell me my mistake https://code.sololearn.com/Wu0dTrFNXnpA/?ref=app

27th Jan 2021, 2:03 PM
Uchiha
8 Answers
+ 4
What do you mean by printing it's "content"?
27th Jan 2021, 2:09 PM
Ezra Bridger 2207 [INACTIVE]
Ezra Bridger 2207 [INACTIVE] - avatar
+ 4
Make that children from childNodes. children creates only elements list but childNodes creates a list of textNode and elements.
27th Jan 2021, 2:11 PM
Abhay
Abhay - avatar
+ 3
childNodes is used to access all nodes, while children filter only elements (tags) nodes... the last is useful for only walking tags, while the first is useful if you need to access any other nodes (text nodes, comments...) the last is commonly enough and even preferable (think of a document where tags are indented against minified/inlined version without spaces between tags: the first has text nodes between tags, but not the last: children equals childNodes for the last, but not the first)
27th Jan 2021, 7:48 PM
visph
visph - avatar
+ 1
Abhay thanks it worked after I made the change. If the childNodes method creates a list of elements and text nodes what is it used for?
27th Jan 2021, 2:23 PM
Uchiha
+ 1
Uchiha sorry! ,but I don't know.
27th Jan 2021, 2:28 PM
Abhay
Abhay - avatar
0
Ezra Bridger 2207 sorry I meant 'change its content' thanks for letting me know
27th Jan 2021, 2:18 PM
Uchiha
0
Abhay No problem, thank you for all the help
27th Jan 2021, 4:10 PM
Uchiha
0
visph Thank you
28th Jan 2021, 1:32 PM
Uchiha