-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
51 lines (51 loc) · 1.24 KB
/
script.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
var userinput=document.getElementById("iteminput");
var list1=document.getElementById("list");
function addtheitem(){
var value1 = userinput.value.trim();
if(value1=="")
{
alert("please enter the text");
}
else
{
var listitem=document.createElement("li");
listitem.textContent=value1;
list1.appendChild(listitem);
var deleteicon=document.createElement("span");
deleteicon.className="delete";
deleteicon.innerHTML="✖";
listitem.appendChild(deleteicon);
}
userinput.value = "";
savedata();
}
list1.addEventListener("click",elementclicked);
function elementclicked(event)
{
if(event.target.matches("li"))
{
if(event.target.classList.contains("check"))
{
event.target.classList.remove("check");
}
else
event.target.classList.add("check");
}
else
if(event.target.matches("span"))
{
var parentlist=event.target.parentElement;
if(parentlist)
{
parentlist.remove();
}
}
savedata();
}
function savedata(){
localStorage.setItem("data",list1.innerHTML);
}
function showtask(){
list1.innerHTML=localStorage.getItem("data");
}
showtask();