-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (24 loc) · 839 Bytes
/
app.js
File metadata and controls
30 lines (24 loc) · 839 Bytes
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
// Function to add a new task
function addTask() {
var taskInput = document.getElementById("taskInput");
var taskList = document.getElementById("taskList");
if (taskInput.value.trim() === "") {
alert("Please enter a task!");
return;
}
// Create a new list item
var listItem = document.createElement("li");
listItem.textContent = taskInput.value;
// Create a delete button
var deleteButton = document.createElement("button");
deleteButton.textContent = "Delete";
deleteButton.onclick = function () {
taskList.removeChild(listItem);
};
// Append the delete button to the list item
listItem.appendChild(deleteButton);
// Append the list item to the task list
taskList.appendChild(listItem);
// Clear the input field
taskInput.value = "";
}