-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
44 lines (38 loc) · 1.13 KB
/
main.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
const inputval= document.getElementsByClassName('inputVal')[0];
const addTaskBtn = document.getElementByClassName('btn')[0];
addTaskBtn.addEventListener('click',() =>{
let localItems= JSON.parse(localStorage.getItem('localItem'))
if(localItems === null){
taskList = []
}else{
taskList = localItems;
}
taskList.push(inputval.value)
localStorage.setItem('localItem',JSON.stringify(taslList))
})
function showList(){
let output ='';
let taskListShow = document.querySelector('.todoListItem')
let localItems = JSON.parse( localStorage.getItem('localItem'))
if(localItems === null){
taskList =[]
}
else{
taskList = localItems;
}
taskList.forEach((data ,index) => {
<div class ="todoList">
<p class ="pText">movies tonight</p>
<button class ="deleteTask "onClick ="deleteItem(${index})">x</button>
</div>
}
);
taskListShow.innerHTML =output;
}
showList()
function deleteItem(index)
showList()
function clearTask(){
localStorage.clear()
showItem()
}