Hey everyone,
I need help with coding a filter in JavaScript and I'm running into an error (Uncaught TypeError: todos.forEach is not a function) that I can't figure out. Can someone assist me in resolving this issue?
const todoFilter = document.querySelector('.todoFilter');
todoFilter.addEventListener("click", deneme);
function deneme(e) {
const todos = todoField.children;
todos.forEach(element => {
if (e.target.value = "all") {
element.style.display = 'flex';
} else if (e.target.value = "completed") {
element.style.display = 'flex';
} else {
element.style.display = 'none';
}
});
}
<section class="addField">
<form>
<div class="select">
<select name="options" class="todoFilter">
<option value="all">All</option>
<option value="completed">Completed</option>
<option value="deleted">Deleted</option>
</select>
</div>
</form>
</section>
<section class="todolist">
<ul class="todos">
<div class="todo">
<li>1</li>
<button class="completeButton">Complete</button>
<button class="deleteButton">Delete</button>
</div>
<div class="todo completed">
<li>2</li>
<button class="completeButton">Complete</button>
<button class="deleteButton">Delete</button>
</div>
</ul>
</section>