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 trial

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perform: Traversing Elements with querySelector

marcus shipman
marcus shipman
8,686 Points

Uncaught 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]

Seth Kroger
Seth Kroger
56,413 Points

To 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...

ยดยดยด

4 Answers

Jason Berteotti
Jason Berteotti
12,352 Points

no, 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
marcus shipman
8,686 Points

let 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
Seth Kroger
56,413 Points

The 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
marcus shipman
8,686 Points

ok, thank you Seth and Jason