-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
28 lines (23 loc) · 762 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const search = document.querySelector('#search');
const todos = document.querySelectorAll('ul li');
const notFound = document.querySelector('#notFound');
search.addEventListener('keyup', filterFunctionality);
function filterFunctionality(e) {
let searching = e.target.value.toLowerCase();
// Filters the todo
[...todos].forEach(todo => {
let todoContent = todo.textContent;
if (todoContent.toLowerCase().includes(searching)) {
todo.style.display = 'block';
} else {
todo.style.display = 'none';
}
});
// Displays No Todo Found
let result = [...todos].every(todo => {
return todo.style.display === 'none';
});
result === true
? (notFound.style.display = 'block')
: (notFound.style.display = 'none');
}