-
Notifications
You must be signed in to change notification settings - Fork 0
/
script1.js
39 lines (32 loc) · 909 Bytes
/
script1.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
let input = document.getElementById("input");
let addbutton = document.getElementById("addbutton");
let list = document.getElementById("list")
addbutton.addEventListener("click" , () =>{
if (input.value !== "")
{
const tasktext = input.value;
let listitem = document.createElement("li")
listitem.innerHTML =`${tasktext}
<button class ="deletebutton">Delete</button>`
list.appendChild(listitem)
}
else{
alert("You must write Something")
}
input.value= "";
save();
})
list.addEventListener("click" ,(event) => {
if(event.target.classList.contains("deletebutton")){
const listb = event.target.parentElement;
list.removeChild(listb)
}
save();
})
function save(){
localStorage.setItem("data" , list.innerHTML);
}
function show(){
list.innerHTML = localStorage.getItem("data");
}
show();