-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (28 loc) · 937 Bytes
/
app.js
File metadata and controls
35 lines (28 loc) · 937 Bytes
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
function addTodoItems() {
let todoText = document.getElementById("todoText");
if (todoText.value.trim() === "") {
Swal.fire("Please enter a value!");
return;
} else {
let todoList = document.getElementById("todoList");
let todoItem = `<li class="todoItems">${todoText.value}
<i onclick="deleteSingleTodo()" class="fa-solid fa-xmark"></i></li>`;
todoList.innerHTML += todoItem;
todoText.value = "";
}
}
function deleteSingleTodo() {
event.target.parentElement.remove();
}
function deleteAllTodoElem() {
let todoList = document.getElementById("todoList");
if (todoList.children.length === 0) {
Swal.fire("No items to delete!");
return;
}
for (let i = 0; i < todoList.children.length; i++) {
todoList.children[i].remove();
i--;
}
Swal.fire("All items deleted!");
}