-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (22 loc) · 936 Bytes
/
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
document.getElementById('addTaskButton').addEventListener('click', addTask);
function addTask() {
const taskInput = document.getElementById('taskInput');
const taskText = taskInput.value.trim();
if (taskText !== '') {
const taskList = document.getElementById('taskList');
const listItem = document.createElement('li');
listItem.textContent = taskText;
const deleteButton = document.createElement('button');
deleteButton.textContent = 'Delete';
deleteButton.classList.add('delete');
deleteButton.addEventListener('click', function() {
taskList.removeChild(listItem);
});
listItem.addEventListener('click', function() {
listItem.classList.toggle('completed');
});
listItem.appendChild(deleteButton);
taskList.appendChild(listItem);
taskInput.value = '';
}
}