-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
54 lines (37 loc) · 1.18 KB
/
main.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
54
let IdCounter = 0;
const input = document.querySelector('input[type="text"]');
userInput.addEventListener('submit', (event) =>{
event.preventDefault();
addTask();
});
let addTask = ()=>{
IdCounter++;
let newValue = input.value;
list.innerHTML +=
`<div class="task-container" id="${IdCounter}">
<label>
<input type="checkbox">
${newValue}
</label>
<img src="https://cdn-icons-png.flaticon.com/512/542/542775.png" alt="Icono" class="classBtn">
</div>`
input.value = "";
updateStats();
}
list.addEventListener('click', (event)=>{
if(event.srcElement.nodeName == 'INPUT'){
updateStats();
}else if(event.srcElement.nodeName == 'IMG'){
deleteTask(event.srcElement.parentNode.id);
}
})
let updateStats = ()=>{
let element = list.querySelectorAll('div');
let checkbox = list.querySelectorAll('input[type="checkbox"]:checked');
stats.innerHTML = `<p>Tareas pendientes: ${element.length} Completadas: ${checkbox.length}</p>`
}
let deleteTask = (id)=>{
let taskToDelete = document.getElementById(id);
list.removeChild(taskToDelete);
updateStats();
}