-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
48 lines (37 loc) · 1.28 KB
/
index.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const addTodos = document.querySelector(".add");
const ul = document.querySelector(".todos");
const searchInput = document.querySelector(".searcher");
// ADDING NEW TODOS
addTodos.addEventListener("submit", (event) => {
event.preventDefault();
const todo = addTodos.add.value.trim();
if (todo.length > 0) {
const html = `
<li class="list-group-item d-flex justify-content-between align-items-center text-light py-3">
<span>${todo}</span>
<i class="far fa-trash-alt delete"></i>
</li>
`;
ul.innerHTML += html;
addTodos.reset();
}
});
// SEARCH SECTION
const searchTodos = (value) => {
Array.from(ul.children)
.filter(todo => !todo.textContent.toLowerCase().includes(value))
.forEach(todo => todo.classList.add("filtered"));
Array.from(ul.children)
.filter(todo => todo.textContent.toLowerCase().includes(value))
.forEach(todo => todo.classList.remove("filtered"));
};
searchInput.addEventListener("keyup", e => {
const value = searchInput.value.trim().toLowerCase();
searchTodos(value);
});
// DELETING TODOS
ul.addEventListener("click", event => {
if (event.target.classList.contains("delete")) {
event.target.parentElement.remove();
}
});