Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
Traversing the DOM error
Hey Guys, Iām having trouble getting the textContent of some of my elements. The error occurs at line 91. It says the value is undefined, but I have text inside me span tag classes title in my DOM. I also get an error at line 102 and says that ācannot read property of first child of undefinedā. Iām not sure whatās going on. Iāve been trying to troubleshoot the issue for the past hour and half. Any insight is greatly appreciated. Thanks in advance for any of you guys insight! https://code.sololearn.com/W3SW4j88lCjW/?ref=app
3 Respostas
+ 4
Brian Oliver
You need an '#' on line 11
You also need to use previousElementSibling and firstChildSibling on line 93
"The difference between this property and previousSibling is that previousSibling returns the previous sibling node as an element node, a text node or a comment node, while previousElementSibling returns the previous sibling node as an element node (ignores text and comment nodes)."
source - https://www.w3schools.com/jsref/prop_element_previouselementsibling.asp
And at line 12 "let editedListItem;" is assigned to nothing hence the null error at line 102
+ 1
Thank you ODLNT! I did not know that about the previousSibling. Thank you for looking over my code and adding your insight.
+ 1
Brian
You're welcome. I'm glad I was able to help.