-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (30 loc) · 1 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
const tasksDiv = document.querySelector(".tasks");
const taskInput = document.getElementById("taskInput");
function handleAdded() {
const taskTitle = taskInput.value.trim();
if (taskTitle == "") {
alert("Please enter a new task.");
} else {
const taskTemplateDiv = document.getElementById("taskTemplate");
const newTaskDiv = taskTemplateDiv.cloneNode(true);
newTaskDiv.removeAttribute("id");
newTaskDiv.classList.remove("none");
newTaskDiv.querySelector("span").innerText = taskTitle;
tasksDiv.appendChild(newTaskDiv);
}
taskInput.value = "";
}
taskInput.addEventListener("keyup", ({ key }) => {
if (key === "Enter") {
handleAdded();
taskInput.blur();
}
});
function handleCompleted(completeBtn) {
completeBtn.closest(".task").querySelector("span").classList.add("crossed");
completeBtn.classList.add("crossed");
completeBtn.nextElementSibling.classList.add("crossed");
}
function handleRemoved(removeBtn) {
tasksDiv.removeChild(removeBtn.closest(".task"));
}