-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
60 lines (50 loc) · 2.13 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
49
50
51
52
53
54
55
56
57
58
59
60
const todoForm = document.getElementById('todoForm');
const taskInput = document.getElementById('taskInput');
const taskList = document.getElementById('taskList');
todoForm.addEventListener('submit', function(event) {
event.preventDefault();
const taskText = taskInput.value.trim();
if (taskText !== '') {
addTask(taskText);
taskInput.value = '';
}
});
function addTask(taskText) {
const taskItem = document.createElement('li');
taskItem.classList.add('task-item');
const taskTextSpan = document.createElement('span');
taskTextSpan.textContent = taskText;
taskTextSpan.classList.add('task-text');
const statusSpan = document.createElement('span');
statusSpan.textContent = 'Pending';
statusSpan.classList.add('status', 'status-pending');
const actionsDiv = document.createElement('div');
actionsDiv.classList.add('task-actions');
const completeButton = document.createElement('button');
completeButton.textContent = 'Complete';
completeButton.classList.add('complete-button');
completeButton.addEventListener('click', function() {
taskItem.classList.toggle('task-completed');
if (taskItem.classList.contains('task-completed')) {
statusSpan.textContent = 'Completed';
statusSpan.classList.remove('status-pending');
statusSpan.classList.add('status-completed');
} else {
statusSpan.textContent = 'Pending';
statusSpan.classList.remove('status-completed');
statusSpan.classList.add('status-pending');
}
});
const deleteButton = document.createElement('button');
deleteButton.textContent = 'Delete';
deleteButton.classList.add('delete-button');
deleteButton.addEventListener('click', function() {
taskItem.remove();
});
actionsDiv.appendChild(completeButton);
actionsDiv.appendChild(deleteButton);
taskItem.appendChild(taskTextSpan);
taskItem.appendChild(statusSpan);
taskItem.appendChild(actionsDiv);
taskList.appendChild(taskItem);
}