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
Chris Feltus
3,970 PointsSyntax Error: Cannot read property 'children' of null
Having an issue with a syntax error I can't seem to figure out working through the build a to-do app in javascript. The error reports "Cannot read property 'children' of null".
Here is the code
var taskInput = document.getElementById('new-task');
var addButton = document.getElementsByTagName('button')[0];
var incompleteTasksHolder = document.getElementById('incomplete-tasks'); //ul #incomplete-tasks
var completedTasksHolder = document.getElementById('complete-tasks');
//event handlers
var addTask = function () {
console.log('add task...');
}
var editTask = function () {
console.log('edit task...');
}
var deleteTask = function() {
console.log('delete task...');
}
var taskCompleted = function () {
console.log('task completed...');
}
var taskIncomplete = function () {
console.log('task incomplete');
}
var bindTaskEvents = function(taskListItem, checkBoxEventHandler) {
console.log('bind list item events');
}
for (var i = 0; i < incompleteTasksHolder.children.length; i++) {
bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);
}
for (var i = 0; i < completedTasksHolder.children.length; i++) {
bindTaskEvents(completedTasksHolder.children[i], taskIncomplete);
}
The error is pointing to this line specifically
for (var i = 0; i < completedTasksHolder.children.length; i++) {
Not sure why the syntax error is reporting the children is null. It contains items. As shown here in the html
<ul id="completed-tasks">
<li>
<input type="checkbox" checked>
<label>See the Doctor</label>
<input type="text">
<button class="edit">Edit</button>
<button class="delete">Delete</button>
</li>
</ul>
</div><!--completed tasks-->
1 Answer
Chris Feltus
3,970 PointsPretty stupid mistake, just noticed I left of a d: complete*d*-tasks