Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmarcus shipman
8,686 PointsUncaught TypeError: Cannot read property 'children' of null
The error response at the top is for this code, and I type and copy several different ways and still got the same error. Can someone give an ideal as to why?
for(var i = 0; i < incompleteTaskHolder.children.length; i++){
bindTaskEvents(incompleteTaskHolder.children[i], taskIncomplete);
}
[edited for code formatting]
4 Answers
Jason Berteotti
12,352 Pointsno, that definitely would not work. Looks like you deleted a fair portion of your for loop and shifted the loop contents into it.
for (i = 0; i < 10; i++) { console.log(i); }
would log out 0-9 for instance.
marcus shipman
8,686 Pointslet me try again, this is the code I have
for(var i = 0; i < incompleteTaskHolder.children.length; i++){ //bind events to list item's children (taskIncompleted) bindTaskEvents(incompleteTaskHolder.children[i], taskIncomplete); }
Seth Kroger
56,414 PointsThe problem is you didn't actually get anything for incompleteTaskHolder, hence it's nothing, or null in programming terms. Because "nothing" has no properties, like children, you'll get a runtime error when you try to access them but the actual mistake is further up the code where you set incompleteTaskHolder.
marcus shipman
8,686 Pointsok, thank you Seth and Jason
Seth Kroger
56,414 PointsSeth Kroger
56,414 PointsTo show a code block surround it with 3 backticks (the key just left of the number 1 on US keyboards) on separate lines like this:
ยดยดยดjs [code language is optional]
// code goes here...
ยดยดยด