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
Owa Aquino
19,277 PointsStuck on my To-Do App.
Hi Community!
I'm creating my own To Do App after learning from Andrews Course in JavaScript.. And I wanted to create it on my own process without replicating his method. I got stuck in Deletion / Removing of an Item.
At first, I was able to Delete the default Item in my list. But my newly added Item cant be removed and so are the items in the Completed list.
Here is a Snapshot of my current progress : http://w.trhou.se/gieezagn82
I will really appreciate your help!
Thanks!
1 Answer
Steven Parker
243,656 Points
The delete buttons (except for the first) are missing click event handlers.
Instead of using querySelector to find only the first delete button, you could use querySelectorAll to find them all and then use a loop to assign a click handler to each one:
var allDeleteBtns = document.querySelectorAll("button.delete");
for (deleteBtn of allDeleteBtns)
deleteBtn.onclick = removeItem;
Then, you just need to be sure each newly created task gets a click handler on its button. In createNewTaskElements, do this when you are assigning the other properties to deleteBtn:
deleteBtn.onclick = removeItem; //add a click event handler to the button
Owa Aquino
19,277 PointsOwa Aquino
19,277 PointsHi Steve!
Thank you very much! it works. To tell you the truth I don't really still understand it. Sorry, I'm new in JavaScript so I'm still figuring it how and why it works. I have read your answer a hundred times already but can't really figure it out.
My next question (sorry that i have so many follow up questions) is this.
Thank you again for your help, as of now I was able to remove the new added tasks and old task.