-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (27 loc) · 1.08 KB
/
Copy pathindex.js
File metadata and controls
49 lines (27 loc) · 1.08 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
44
45
46
47
48
49
function addTask() {
const taskInput = document.getElementById('inputTask');
const taskText = taskInput.value.trim();
// Check if the input is empty
if (taskText === "") {
alert("Please enter a task before adding.");
return;
}
const newTask = document.createElement('li');
const Tasklist = document.getElementById('Tasklist');
newTask.textContent = document.getElementById('inputTask').value;
const taskSpan = document.createElement('span');
const doneBtn = document.createElement('button');
doneBtn.textContent = "Done";
doneBtn.onclick = function() {
newTask.classList.toggle("done");
};
const deleteBtn = document.createElement('button');
deleteBtn.textContent = "Delete";
deleteBtn.onclick = function() {
Tasklist.removeChild(newTask);
};
newTask.appendChild(doneBtn);
newTask.appendChild(deleteBtn);
Tasklist.appendChild(newTask);
document.getElementById('inputTask').value = "";
}