-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (35 loc) · 1.18 KB
/
Copy pathscript.js
File metadata and controls
61 lines (35 loc) · 1.18 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
const boton = document.querySelector(".fa-plus");
const ul = document.querySelector("ul");
const empty = document.querySelector(".empty");
const input = document.querySelector("#entrada");
boton.addEventListener("click", function(){
if(input.value !== ""){
crearElementos();
}
input.value = "";
input.focus();
})
function crearElementos(){
empty.classList.add("empty-close")
const text = input.value;
const li = document.createElement("li");
const p = document.createElement("p");
p.textContent = text;
li.appendChild(p);
li.appendChild(addDeleteBtn());
ul.appendChild(li);
}
function addDeleteBtn(){
const btnDelete = document.createElement("button");
btnDelete.textContent = "x";
btnDelete.classList.add("styleDelete");
btnDelete.addEventListener("click", (e) =>{
const item = e.target.parentElement;
ul.removeChild(item);
const items = document.querySelectorAll("li");
if(items.length === 0){
empty.classList.remove("empty-close");
}
});
return btnDelete;
}