-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (30 loc) · 1.17 KB
/
script.js
File metadata and controls
36 lines (30 loc) · 1.17 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
const taskInput = document.getElementById("task-input");
const addTaskButton = document.getElementById("add-task");
const taskList = document.getElementById("task-list");
addTaskButton.addEventListener("click", function () {
const taskText = taskInput.value;
if (taskText === "") {
alert("Please enter a task!");
return;
}
const taskItem = document.createElement("li");
taskItem.textContent = taskText;
const deleteButton = document.createElement("button");
deleteButton.textContent = "Delete";
deleteButton.style.backgroundColor = "#FF4C4C";
deleteButton.style.color = "white";
deleteButton.style.border = "none";
deleteButton.style.cursor = "pointer";
deleteButton.addEventListener("click", function () {
taskList.removeChild(taskItem);
});
taskItem.appendChild(deleteButton);
taskList.appendChild(taskItem);
taskInput.value = "";
});
// Bonus: Mark tasks as complete
taskList.addEventListener("click", function (event) {
if (event.target.tagName === 'LI') {
event.target.style.textDecoration = event.target.style.textDecoration === "line-through" ? "none" : "line-through";
}
});