-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (34 loc) · 1.16 KB
/
Copy pathscript.js
File metadata and controls
43 lines (34 loc) · 1.16 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
function addTask() {
let input = document.getElementById("taskInput");
let taskText = input.value.trim();
if (taskText === "") {
alert("Please enter a task!");
return;
}
let li = document.createElement("li");
let span = document.createElement("span");
span.className = "task-text";
span.innerText = taskText;
let actions = document.createElement("div");
actions.className = "actions";
let editBtn = document.createElement("button");
editBtn.innerText = "Edit";
editBtn.onclick = function () {
let newTask = prompt("Edit task:", span.innerText);
if (newTask !== null && newTask.trim() !== "") {
span.innerText = newTask;
}
};
let deleteBtn = document.createElement("button");
deleteBtn.innerText = "Delete";
deleteBtn.className = "delete";
deleteBtn.onclick = function () {
li.remove();
};
actions.appendChild(editBtn);
actions.appendChild(deleteBtn);
li.appendChild(span);
li.appendChild(actions);
document.getElementById("taskList").appendChild(li);
input.value = "";
}