-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (38 loc) · 1.31 KB
/
index.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
55
56
57
58
59
60
61
62
63
const input = document.querySelector('input');
const addBtn = document.querySelector('.btn-add');
const ul = document.querySelector('ul');
const empty = document.querySelector('.empty');
const valorOriginal= empty.textContent;
addBtn.addEventListener("click", (e)=>{
e.preventDefault();
const text=input.value;
if (text !=="" && text !==' '){
console.log("bien");
const li=document.createElement('li');
const p=document.createElement('p');
p.textContent=text;
ul.appendChild(li);
li.appendChild(addDeleteBtn());
li.appendChild(p);
input.value="";
empty.style.display="none";
}
else (text =="" && text ==' ')
console.log('error');
empty.textContent="No es posible crear una tarea vacia.";
})
function addDeleteBtn(){
const deleteBtn= document.createElement('button');
deleteBtn.textContent="X";
deleteBtn.className="delete-btn";
deleteBtn.addEventListener('click',(e)=>{
const li= e.target.parentElement; /*el padre es el li que contiene al button*/
ul.removeChild(li);
const lis= document.querySelectorAll('li');
if(lis.length===0){
empty.style.display="block";
empty.textContent= valorOriginal;
}
});
return deleteBtn;
}