-
Notifications
You must be signed in to change notification settings - Fork 0
/
showTasks.js
33 lines (32 loc) · 1.05 KB
/
showTasks.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
var tasks = JSON.parse(localStorage.getItem("tasks"));
if(tasks !== null)
{
var deletedTasks = JSON.parse(localStorage.getItem("deletedTasks"));
console.log(deletedTasks);
if (deletedTasks === null)
{
deletedTasks = [];
}
for (var i = 0; i < deletedTasks.length; ++i)
{
tasks.splice(deletedTasks[i], 1);
}
deletedTasks = [];
localStorage.setItem("deletedTasks", JSON.stringify(deletedTasks));
localStorage.setItem("tasks", JSON.stringify(tasks))
for(let x = 0; x < tasks.length; x++)
{
var para = document.createElement("div");
para.id = `deleteDiv${x}`
console.log(para);
para.innerHTML = `<p>${tasks[x]}</p>
<button type="button" id = "deleteTask${x}">X</button>`
document.getElementById("updSched").appendChild(para);
document.getElementById(`deleteTask${x}`).onclick = () => {
var elem = document.querySelector(`#deleteDiv${x}`);
elem.parentNode.removeChild(elem);
deletedTasks.push(x);
localStorage.setItem("deletedTasks", JSON.stringify(deletedTasks));
}
}
}