+ 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

6th Feb 2019, 1:37 AM
Brian Oliver
Brian Oliver - avatar
3 ответов
+ 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
6th Feb 2019, 4:52 AM
ODLNT
ODLNT - avatar
+ 1
Thank you ODLNT! I did not know that about the previousSibling. Thank you for looking over my code and adding your insight.
6th Feb 2019, 5:33 AM
Brian Oliver
Brian Oliver - avatar
+ 1
Brian You're welcome. I'm glad I was able to help.
6th Feb 2019, 5:39 AM
ODLNT
ODLNT - avatar