I'm doing a todo List and I'm stuck in filtering the list items of the todos list. I'm not even sure where the problem is.
I create a list item and when clicking the check icon I add a class of "completed" to it and in another function I iterate the list childNotes and try to filter the ones that have that completed class but keep getting an error of:
"Uncaught TypeError: Cannot set property 'display' of undefined at app.js:84. at NodeList.forEach () at HTMLSelectElement.filterTodo (app.js:76)" even thought the list has list items
code : https://codepen.io/mullerz/pen/vYNeMEO?editors=1111
if(item.classList[0] === "complete-btn"){
const todo = item.parentElement;
todo.classList.toggle("completed");
}
}
function filterTodo(e){
const todos = todoList.childNodes;
//console.log(todos)
todos.forEach(function(todo, index){
//if(index === 0){return}
console.log({todo})
switch (e.target.value) {
case "all" :
console.log(todo.classList)
todo.style.display = "flex";
break;
case "completed" :
if(todo.classList.contains("completed") ){
console.log(todo.classList)
todo.style.display = "flex";
}
else{
todo.style.display = "none";
}
```