-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (35 loc) · 1.37 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const inputFields = document.getElementById('inputField')
const inputButton = document.getElementById('submitButton');
const todoList = document.getElementById('todo-list');
inputButton.addEventListener('click',function(e){
e.preventDefault();
// create a todo div element with class todo
const todoDiv = document.createElement('div')
todoDiv.classList.add('todo');
// Create LI element with todo-item class
const newTodoLi = document.createElement('li');
newTodoLi.classList.add("todo-item")
todoDiv.appendChild(newTodoLi)
newTodoLi.innerText = inputFields.value;
inputFields.value = '';
// Check Button
const completeButton = document.createElement('button');
completeButton.innerHTML = '<i class="fa-solid fa-pen-to-square"></i>';
completeButton.classList.add('complete-btn');
todoDiv.appendChild(completeButton)
// Delete Button
const trashButton = document.createElement('button');
trashButton.innerHTML = '<i class="fas fa-trash"></i>';
trashButton.classList.add('remove-btn');
todoDiv.appendChild(trashButton)
// Apped To List
todoList.appendChild(todoDiv)
})
// Delete The List
todoList.addEventListener('click',function(e){
const delItem = e.target;
if(delItem.classList[0] === 'remove-btn'){
const todo = delItem.parentElement;
todo.remove()
}
})