forked from P2003H/TO-DO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
33 lines (28 loc) · 884 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
30
31
32
33
let todoList = [];
function addTodo() {
let todoInput = document.getElementById('todoInput');
let todoText = todoInput.value.trim();
if (todoText !== '') {
todoList.push(todoText);
todoInput.value = '';
displayTodos();
}
}
function deleteTodo(index) {
todoList.splice(index, 1);
displayTodos();
}
function displayTodos() {
let todoListUl = document.getElementById('todoList');
todoListUl.innerHTML = '';
todoList.forEach((todo, index) => {
let li = document.createElement('li');
li.textContent = todo;
let deleteButton = document.createElement('span');
deleteButton.textContent = '❌';
deleteButton.classList.add('delete');
deleteButton.setAttribute('onclick', `deleteTodo(${index})`);
li.appendChild(deleteButton);
todoListUl.appendChild(li);
});
}