Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perfect

1 Answer

Simon Coates
Simon Coates
28,692 Points

Can you clarify what you mean? I just converted my solution to use arrows. it's not a complete solution (because i was feeling lazy that day), but it's in javascript, so can use any part of the language implemented in the browser.

    const add = document.querySelector("#add");
    const incomplete = document.getElementById("incomplete-tasks");
    const complete = document.getElementById("completed-tasks");
    add.addEventListener("click",  (e) => {
        var text = document.getElementById("new-task").value;        
        var parent = incomplete;
        parent.innerHTML += '<li><input type="checkbox"><label>'+text+'</label><input type="text"><button class="edit">Edit</button><button class="delete">Delete</button></li>'
        /*
        var li = document.createElement('li'); 
        li.textContent = text;
        parent.appendChild(li);
        */
    });
    incomplete.addEventListener("click",  (ev) => {
        var target = ev.target;
        var parent = target.parentElement;
        if(target.tagName == "BUTTON"){
            if(target.classList.contains('edit')){
                if(parent.classList.contains('editMode'))
                    parent.classList.remove('editMode');
                else parent.classList.add('editMode');

            } else {
                this.removeChild(parent);
            }
        }
    });
    incomplete.addEventListener("change",  (e) => {
        if(e.target.tagName == "INPUT" && e.target.type=="checkbox"){
            if(e.target.checked){
                complete.appendChild(e.target.parentElement);
            }
        }
    });
/*
    complete.addEventListener("change", function(e) {
        if(e.target.tagName == "INPUT" && e.target.type=="checkbox"){           
            incomplete.appendChild(e.target.parentElement);           
        }
    });
*/
    complete.addEventListener("change", (e) => {
        if(e.target.tagName == "INPUT" && e.target.type=="checkbox"){           
            incomplete.appendChild(e.target.parentElement);           
        }
    });

nb: unless my memory is off, my solution may rely on event bubbling, so differs a little in concept from Andrew's code.