-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo.js
More file actions
69 lines (52 loc) · 2.33 KB
/
todo.js
File metadata and controls
69 lines (52 loc) · 2.33 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
window.addEventListener('load', () => {
const form = document.querySelector("#taskForm");
const input = document.querySelector("#newTaskInput");
const list_el = document.querySelector("#tasks");
form.addEventListener('submit', (e) => {
e.preventDefault();
const task = input.value;
if (!task) {
alert("Please fill out the task");
return;
}
const task_el = document.createElement("div");
task_el.classList.add("task");
const task_content_el = document.createElement("div");
task_content_el.classList.add("content");
task_el.appendChild(task_content_el);
const task_input_el = document.createElement("input");
task_input_el.classList.add("text");
task_input_el.type = "text";
task_input_el.value = task;
task_input_el.setAttribute("readonly", "readonly");
task_content_el.appendChild(task_input_el);
//The above is for adding a task in
// Takes an input and makes it into a list element (Its the task itself)
const task_action_el = document.createElement("div");
task_action_el.classList.add("actions");
const trashIcon = document.createElement("button");
trashIcon.innerHTML = '<i class="fa-solid fa-trash-can"></i>';
trashIcon.classList.add("trash-button");
const editIcon = document.createElement("button");
editIcon.innerHTML = '<i class="fa-solid fa-pencil"></i>';
editIcon.classList.add("edit-button");
task_action_el.appendChild(editIcon);
task_action_el.appendChild(trashIcon);
task_el.appendChild(task_action_el);
list_el.appendChild(task_el);
input.value = "";
trashIcon.addEventListener('click', () => {
list_el.removeChild(task_el);
});
editIcon.addEventListener('click', () => {
if (editIcon.innerHTML == '<i class="fa-solid fa-pencil"></i>') {
task_input_el.removeAttribute("readonly");
task_input_el.focus();
editIcon.innerHTML = '<i class="fa-solid fa-floppy-disk"></i>';
} else {
task_input_el.setAttribute("readonly", "readonly");
editIcon.innerHTML = '<i class="fa-solid fa-pencil"></i>';
}
});
});
});