-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.js
48 lines (37 loc) · 1.56 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
function addTask() {
// Get the task input element
var taskInput = document.getElementById('newTask');
// Get the task list element
var taskList = document.getElementById('taskList');
// Create a new list item element
var listItem = document.createElement('li');
// Create a text node with the task input value
var taskText = document.createTextNode(taskInput.value);
// Create a "Mark as Complete" button element
var completeButton = document.createElement('button');
completeButton.appendChild(document.createTextNode('Mark'));
completeButton.className = 'complete-button';
// Add an event listener to mark the task as complete when the button is clicked
completeButton.addEventListener('click', function () {
listItem.classList.toggle('completed');
});
var deleteButton = document.createElement('button');
deleteButton.appendChild(document.createTextNode('Delete'));
deleteButton.className = 'delete-button';
deleteButton.addEventListener('click', function () {
taskList.removeChild(listItem);
});
// Append taskText and completeButton to the list item
listItem.appendChild(completeButton);
listItem.appendChild(taskText);
listItem.appendChild(deleteButton);
taskList.appendChild(listItem);
// Append the list item to the task list
taskList.appendChild(listItem);
// Clear the task input field
taskInput.value = '';
}
function clearAllTasks() {
var taskList = document.getElementById('taskList');
taskList.innerHTML = ''; // Remove all tasks
}