-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo_modified.js
36 lines (29 loc) · 932 Bytes
/
todo_modified.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
let btn = document.querySelector("button");
let ul = document.querySelector("ul");
let inp = document.querySelector("input");
btn.addEventListener("click", function() {
let item = document.createElement("li");
item.innerText = inp.value;
let del = document.createElement("button");
del.innerText = "delete";
del.classList.add("delete");
item.appendChild(del);
ul.appendChild(item);
console.log(inp.value);
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;
// console.log(par);
// par.remove();
// });
// }