-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
49 lines (40 loc) · 1.74 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
document.addEventListener('DOMContentLoaded', () => {
const todoForm = document.getElementById('todo-form');
const todoInput = document.getElementById('todo-input');
const todoList = document.getElementById('todo-list');
todoForm.addEventListener('submit', (e) => {
e.preventDefault();
addTask(todoInput.value);
todoInput.value = '';
});
function addTask(task) {
if (task.trim() === '') return;
const li = document.createElement('li');
const taskText = document.createElement('p');
taskText.textContent = task;
taskText.classList.add('task-text');
const buttonsContainer = document.createElement('div');
buttonsContainer.style.display = 'flex';
buttonsContainer.style.gap = '10px';
const completeButton = document.createElement('button');
// completeButton.textContent = 'Complete';
completeButton.textContent = '✅'
completeButton.classList.add('complete');
completeButton.addEventListener('click', () => {
taskText.classList.toggle('completed-task');
completeButton.classList.toggle('completed-task');
});
const deleteButton = document.createElement('button');
// deleteButton.textContent = 'Delete';
deleteButton.textContent = '🗑️'
deleteButton.classList.add('delete');
deleteButton.addEventListener('click', () => {
todoList.removeChild(li);
});
buttonsContainer.appendChild(completeButton);
buttonsContainer.appendChild(deleteButton);
li.appendChild(taskText);
li.appendChild(buttonsContainer);
todoList.appendChild(li);
}
});