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

Benjamin Kanter
PLUS
Benjamin Kanter
Courses Plus Student 7,482 Points

Differences in Console returning "Bind list item events" using Chrome 64bit vs 32bit, and editButton failing to bind

I have 2 questions pertaining to this video. I have been working on Chrome 64 bit however I noticed that after completing this video, I was only returning 2 list item events using the console. However after I switched to Chrome 32bit I was able to return all 3. I haven't returned any errors so it has been difficult to determine if this is an issue of compatibility or an issue with my code.

In addition currently the delete button, add button, and check boxes are all returning the console.log, however the editButton is not working when I hit it and not returning anything. I'm not sure what the problem is here as I have been trying to figure it out testing it and I haven't been able to get it to work. It is not returning anything when the button is pressed, no error or console.log.

//Problem: User interaction doesn't provide desired results
//Solution: Add interactivity so the user can manage daily tasks

//******Variables**********//

var taskInput = document.getElementById("new-task"); //new task
var addButton = document.getElementsByTagName("button")[0]; //first button on page, array / indexs start at 0
var incompleteTasksHolder = document.getElementById("incomplete-tasks"); //ul id=incomplete-tasks
var completedTasksHolder = document.getElementById("completed-tasks"); //ul id=completed-tasks


//******Functions******//

//Add a new task
var addTask = function() {
    console.log("Add task...");
    //When the button is pressed
    //Create a new list item with the text from #new-task:
        //input (checkBox)
        //label
        //input (text)
        //button.edit
        //button.delete
        //Each elements, needs modified and appended
}

//Edit an existing task (toggle .editMode)
var editTask = function() {
    console.log("Edit task...");
    //When the edit button is pressed
        //if the class of the parent is .editMode
            //Switch from .editMode
            //label text become the input's value
        //else 
            //Switch to .editMode 
            //input value becomes the label's text

    //Toggle .editMode on the parent
}

//Delete an existing task
var deleteTask = function() {
    console.log("Delete task...");
    //When the Delete button is pressed
        //Remove the parent list item from the ul
}

//Mark a task as complete
var taskCompleted = function() {
    console.log("Task complete...");
    //When the checkbox is checked
        //Append the task list item to the #completed-tasks
}

//Mark a task as incomplete
var taskIncomplete = function() {
    console.log("Task incomplete...");
    //When the checkcbox is unchecked
        //Append the task list item to #incomplete-tasks
}

//*******Wiring**********/
//DRY Code = best practice = Don't repeat yourself

var bindTaskEvents = function(taskListItem, checkBoxEventHandler) {
    console.log("Bind list item events");
    //Select listItem's children
    var checkBox = taskListItem.querySelector("input[type=checkbox]");
    var editButton = taskListItem.querySelector("button.edit");
    var deleteButton = taskListItem.querySelector("button.delete");

    //bind checkBoxEventHandler to the checkbox
    checkBox.onchange = checkBoxEventHandler;

    //bind editTask to edit button
    editButton.onlick = editTask;

    //bind deleteTask to delete button
    deleteButton.onclick = deleteTask;

}

//Set the click Handler to the add task function
addButton.onclick = addTask;


//Cycle over incompleteTasksHolder ul list items
for (var i = 0; i < incompleteTasksHolder.children.length; i++) {
        //bind events to list item's children (taskCompleted)
    bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);
}
//Cycle over completedTasksHolder ul list items
for (var i = 0; i < completedTasksHolder.children.length; i++) {
        //bind events to list item's children (taskIncomplete)
    bindTaskEvents(completedTasksHolder.children[i], taskIncomplete);
}

2 Answers

Hey Benjamin Kanter,

I believe the errors you're seeing are because the "onclick" handler on your editButton under the bindTaskEvents function is currently "onlick", which would be an interesting event handler to see! haha Try adding that c in there to make it click and see what happens. :)

Benjamin Kanter
PLUS
Benjamin Kanter
Courses Plus Student 7,482 Points

Wow I can't believe I missed that I tried retyping it and missed it again too. I should have stuck to autocomplete. Thank you for the help.

Anytime, Benamin! If my answer did the trick, you can mark it as Best Answer so that this will be solved.