-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappToDoList.js
More file actions
59 lines (48 loc) · 1.59 KB
/
Copy pathappToDoList.js
File metadata and controls
59 lines (48 loc) · 1.59 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
(function(){
// Variables
var lista = document.getElementById("lista"),
tareaInput = document.getElementById("tareaInput"),
btnNuevaTarea = document.getElementById("btn-agregar");
// Funciones
var agregarTarea = function(){
var tarea = tareaInput.value,
nuevaTarea = document.createElement("li"),
enlace = document.createElement("a"),
contenido = document.createTextNode(tarea);
if (tarea === "") {
tareaInput.setAttribute("placeholder", "Agrega una tarea valida");
tareaInput.className = "error";
return false;
}
// Agregamos el contenido al enlace
enlace.appendChild(contenido);
// Le establecemos un atributo href
enlace.setAttribute("href", "#");
// Agrergamos el enlace (a) a la nueva tarea (li)
nuevaTarea.appendChild(enlace);
// Agregamos la nueva tarea a la lista
lista.appendChild(nuevaTarea);
tareaInput.value = "";
for (var i = 0; i <= lista.children.length -1; i++) {
lista.children[i].addEventListener("click", function(){
this.parentNode.removeChild(this);
});
}
};
var comprobarInput = function(){
tareaInput.className = "";
teareaInput.setAttribute("placeholder", "Agrega tu tarea");
};
var deleteTask = function(){
this.parentNode.removeChild(this);
};
// Eventos
// Agregar Tarea
btnNuevaTarea.addEventListener("click", agregarTarea);
// Comprobar Input
tareaInput.addEventListener("click", comprobarInput);
// Borrando Elementos de la lista
for (var i = 0; i <= lista.children.length -1; i++) {
lista.children[i].addEventListener("click", deleteTask);
}
}());