-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (24 loc) · 883 Bytes
/
script.js
File metadata and controls
28 lines (24 loc) · 883 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
function addTodo() {
const input = document.getElementById('todo-input');
const newTodoText = input.value.trim();
if (newTodoText !== '') {
const newTodoItem = document.createElement('li');
newTodoItem.textContent = newTodoText;
newTodoItem.addEventListener('click', toggleComplete);
const removeButton = document.createElement('button');
removeButton.textContent = 'Remove';
removeButton.classList.add('remove-btn');
removeButton.addEventListener('click', removeTodo);
newTodoItem.appendChild(removeButton);
document.getElementById('todo-list').appendChild(newTodoItem);
input.value = '';
}
}
function toggleComplete(event) {
event.target.classList.toggle('completed');
}
function removeTodo(event) {
event.stopPropagation();
const item = event.target.parentNode;
document.getElementById('todo-list').removeChild(item);
}