-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (58 loc) · 2.06 KB
/
script.js
File metadata and controls
68 lines (58 loc) · 2.06 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const btnAgregar = document.getElementById('btnAgregar');
const tarea = document.getElementById('toDo');
const lista = document.getElementById('lista');
const editar = document.getElementById('editar');
const eliminar = document.getElementById('eliminar');
const alertaAgregada = document.getElementById('customAlert');
const btnAlertaAdd = document.getElementById('closeAlert');
const alertaError = document.getElementById('errorAlert');
const btnAlertaError = document.getElementById('cerrarAlerta');
function agregarTarea(){
const nuevoDiv = document.createElement('div');
const checkbox = document.createElement('input');
const textInput = document.createElement('label');
const textInput2 = document.createElement('del');
// nuevoDiv.id=contador;
// checkbox.id=contador++;
nuevoDiv.classList.add('contenedor_tarea')
checkbox.type = 'checkbox';
textInput.textContent = tarea.value;
textInput2.textContent = tarea.value;
textInput2.style.display = 'none';
//ver cómo evalúo cada uno de los checkbox
lista.appendChild(nuevoDiv);
nuevoDiv.appendChild(checkbox);
nuevoDiv.appendChild(textInput);
nuevoDiv.appendChild(textInput2);
prepararNuevaTarea();
checkbox.addEventListener('change', (evento) =>{
if(evento.target.checked){
textInput.style.display = 'none';
textInput2.style.display = 'inline';
nuevoDiv.classList.add('sombreado');
}
else{
textInput2.style.display = 'none';
textInput.style.display = 'inline';
nuevoDiv.classList.remove('sombreado');
}
});
}
function prepararNuevaTarea (){
tarea.value = "";
}
btnAgregar.addEventListener('click', ()=>{
if(tarea.value != ''){
agregarTarea();
alertaAgregada.style.display = 'flex';
}
else{
alertaError.style.display = 'flex';
}
});
btnAlertaAdd.addEventListener('click', () => {
alertaAgregada.style.display = 'none';
});
btnAlertaError.addEventListener('click', () => {
alertaError.style.display = 'none';
});