-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
33 lines (27 loc) · 908 Bytes
/
app.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
let inp = document.querySelector("input");
let btn = document.querySelector("button");
let ul = document.querySelector("ul");
btn.addEventListener("click", function(){
let item = document.createElement("li");
item.innerText = inp.value;
let delBtn = document.createElement("button");
delBtn.innerText = "Delete";
delBtn.classList.add("delete");
item.appendChild(delBtn);
ul.appendChild(item);
inp.value = " ";
});
ul.addEventListener("click", function(event){
if(event.target.nodeName = "BUTTON"){
let listItem= event.target.parentElement;
listItem.remove();
console.log("deleted");
}
});
// let delBtns = document.querySelectorAll(".delete");
// for(delBtn of delBtns){
// delBtn.addEventListener("click", function(){
// let par = this.parentElement;
// par.remove();
// });
// }