-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (35 loc) · 1010 Bytes
/
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
const taskInput = document.querySelector("#task-input");
const taskForm = document.querySelector("#task-form");
const taskList = document.querySelector("#task-list");
taskForm.addEventListener("submit",(e)=>{
e.preventDefault();
const taskTitle = taskInput.value;
const listItem = document.createElement('li');
listItem.innerHTML= taskTitle;
taskList.append(listItem);
let span = document.createElement("span");
span.innerHTML='×';
listItem.appendChild(span);
taskInput.value="";
saveListData();
}
)
taskList.addEventListener("click",(e)=>{
if(e.target.tagName=="LI"){
e.target.classList.toggle("checked");
saveListData();
}
if(e.target.tagName=="SPAN"){
const li =e.target.parentElement;
li.remove();
saveListData();
}
}
);
function showListData(){
taskList.innerHTML=localStorage.getItem('listItem');
}
function saveListData(){
localStorage.setItem('listItem',taskList.innerHTML);
}
showListData();