-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
26 lines (24 loc) · 886 Bytes
/
app.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
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('todo-form');
const todoInput = document.getElementById('new-todo');
const todoList = document.getElementById('todo-list');
form.addEventListener('submit', (e) => {
e.preventDefault();
const newTodoText = todoInput.value.trim();
if (newTodoText !== '') {
addTodoItem(newTodoText);
todoInput.value = '';
}
});
function addTodoItem(text) {
const li = document.createElement('li');
li.textContent = text;
const deleteButton = document.createElement('button');
deleteButton.textContent = 'Delete';
deleteButton.addEventListener('click', () => {
todoList.removeChild(li);
});
li.appendChild(deleteButton);
todoList.appendChild(li);
}
});