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 Perfect

1 Answer

Simon Coates
Simon Coates
28,694 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.