-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
42 lines (31 loc) · 1.17 KB
/
script.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
const buttonNewTask = document.querySelector(".new-task button");
const taskbox = document.querySelector(".task-box");
const newTaskInput = document.querySelector(".new-task input");
buttonNewTask.addEventListener("click", addTask);
function addTask(e) {
e.preventDefault();
const taskItem = document.createElement("div");
taskItem.classList.add("task-item");
const checkboxInput = document.createElement("input");
checkboxInput.type = "checkbox";
const text = newTaskInput.value;
const textItem = document.createElement("p");
textItem.innerText = text;
const buttonTrash = document.createElement("button");
buttonTrash.innerHTML = '<i class="fa fa-trash"></i>';
taskItem.appendChild(checkboxInput);
taskItem.appendChild(textItem);
taskItem.appendChild(buttonTrash);
taskbox.appendChild(taskItem);
buttonTrash.addEventListener("click", deleteTask);
checkboxInput.addEventListener('click', completeTask);
newTaskInput.value = "";
}
function deleteTask(e) {
const buttonTrash = e.target.parentElement;
const element = buttonTrash.parentElement;
element.remove();
}
function completeTask(e) {
e.target.parentElement.classList.toggle("complete");
}