-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (25 loc) · 999 Bytes
/
script.js
File metadata and controls
29 lines (25 loc) · 999 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
29
document.getElementById('add-btn').addEventListener('click', function() {
const input = document.getElementById('todo-input');
const taskText = input.value.trim();
if (taskText) {
const li = document.createElement('li');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.addEventListener('change', function() {
li.classList.toggle('done');
});
const taskTextSpan = document.createElement('span');
taskTextSpan.textContent = taskText;
const removeBtn = document.createElement('button');
removeBtn.textContent = 'Remove';
removeBtn.className = 'remove-btn';
removeBtn.addEventListener('click', function() {
li.remove();
});
li.appendChild(checkbox);
li.appendChild(taskTextSpan);
li.appendChild(removeBtn);
document.getElementById('todo-list').appendChild(li);
input.value = '';
}
});