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 trialedigi135
9,092 PointsShowing no errors, but only addTask button works
Of course I am painstakingly trying to match each line letter for letter, yet I am missing something. I can't seem to figure out what I am doing wrong! Heres my code:
var taskInput = document.getElementById("new-task");
var addButton = document.getElementsByTagName("button")[0];
var incompleteTasksHolder = document.getElementById("incomplete-tasks");
var completedTasksHolder = document.getElementById("completed-tasks");
var addTask = function() {
console.log("Aha!");
};
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");
var checkbox = taskListItem.querySelector("input[type=checkbox]");
var editButton = taskListItem.querySelector("button.edit");
var deleteButton = taskListItem.querySelector("button.delete");
editButton.onclick = editTask;
deleteButton.onclick = deleteTask;
checkbox.onchange = checkboxEventHandler;
};
addButton.onclick = addTask;
for(var i = 0; i < incompleteTasksHolder.length; i++){
bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);
}
for(var i = 0; i < completedTasksHolder.length; i++){
bindTaskEvents(completedTasksHolder.children[i], taskIncomplete);
}
Any hints are appreciated!
2 Answers
Ran ShemTov
14,148 PointsYour post is a little unorganized, but it seems like your querySelector is adressing something wrong. try going for a simple queryselector, like for the deletebutton:
var deleteBtn = document.querySelector('.delete');
as you see i just adressed the delete class, no need for "button" there. I guess no other element but this button, uses this class.
edigi135
9,092 PointsSo it turns out I accidentally forgot a selector in my for loops.
I wrote:
for(var i = 0; i < incompleteTasksHolder.length; i++){
bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);
}
for(var i = 0; i < completedTasksHolder.length; i++){
bindTaskEvents(completedTasksHolder.children[i], taskIncomplete);
}
But I left off the "incompleteTasksHolder.CHILDREN.length" in the parenthesis of the for loops :/
Thanks regardless!