-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
62 lines (50 loc) · 2.06 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const tasksContainer = document.getElementById("tasks");
function addTask() {
const title = document.getElementById("taskTitle").value;
const description = document.getElementById("taskDescription").value;
if (title === "") {
alert("Please enter a title for the task.");
return;
}
const task = document.createElement("div");
task.classList.add("task");
task.innerHTML = `
<h3>${title}</h3>
<p>${description}</p>
<div class="task-actions">
<button class="edit-button" onclick="editTask(this)">Edit</button>
<button class="delete-button" onclick="deleteTask(this)">Delete</button>
<button class="done-button" onclick="markTaskAsDone(this)">Done</button>
</div>
`;
tasksContainer.appendChild(task);
document.getElementById("taskTitle").value = "";
document.getElementById("taskDescription").value = "";
}
function editTask(button) {
const task = button.parentElement.parentElement;
const titleElement = task.querySelector("h3");
const descriptionElement = task.querySelector("p");
const title = titleElement.textContent;
const description = descriptionElement.textContent;
document.getElementById("taskTitle").value = title;
document.getElementById("taskDescription").value = description;
tasksContainer.removeChild(task);
}
function deleteTask(button) {
const task = button.parentElement.parentElement;
tasksContainer.removeChild(task);
}
function markTaskAsDone(button) {
const task = button.parentElement.parentElement;
const description = task.querySelector("p");
if (description.style.textDecoration === "line-through") {
description.style.textDecoration = "none";
task.querySelector("h3").style.textDecoration = "none";
task.style.boxShadow = "0 0 0 transparent";
} else {
description.style.textDecoration = "line-through";
task.querySelector("h3").style.textDecoration = "line-through";
task.style.boxShadow = "0 0 8px var(--done-button-box-color)";
}
}