-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (44 loc) · 1.34 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
48
49
50
51
52
53
let input = document.querySelector('.entered-list');
let addBtn = document.querySelector('.add-list');
let tasks = document.querySelector('.tasks');
// add btn disabled
input.addEventListener('keyup' , () =>{
if (input.value.trim() != 0){
addBtn.classList.add('active');
} else {
addBtn.classList.remove('active');
}
});
// add new item to list
addBtn.addEventListener('click', () =>{
if (input.value.trim() != 0){
let newItem = document.createElement('div');
newItem.classList.add('item');
newItem.innerHTML =
`
<p> ${input.value} </p>
<div class="item-btn">
<i class="fa-solid fa-pen-to-square"></i>
<i class="fa-solid fa-xmark"></i>
</div>
`
tasks.appendChild(newItem);
input.value = '';
}else{
alert('Please enter a tasks')
}
});
// delete item from list
tasks.addEventListener('click', (e) =>{
if (e.target.classList.contains('fa-xmark')) {
e.target.parentElement.parentElement.remove();
}
});
// mark item as completed
tasks.addEventListener('click',(e) =>{
if (e.target.classList.contains('fa-pen-to-square'))
{
e.target.parentElement.parentElement.classList.
toggle('completed');
}
});