Now, what about those crossed-out items? It's going to get very messy if you don't let users clean them up too. They all have the same class—completed
—so you can use that to pick out the items to remove by selecting based on class instead of id. Change clearCompletedToDoItems
like this:function clearCompletedToDoItems() {
var items = document.getElementsByClassName("completed")
for(var i=0; i<items.length; i++){
items[i].remove()
}
}
This code is slightly tricky, but it's getting an a list of all the HTML elements with the completed
class and then using a for
loop