-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatherToDo.js
28 lines (24 loc) · 887 Bytes
/
gatherToDo.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
if(todo === null)
{
todo = [];
}
let initval2 = localStorage.getItem(todo);
console.log(initval2);
document.getElementById("button2").onclick = addNewToDo;
function addNewToDo()
{
todo.push(document.getElementById('do').value);
localStorage.setItem("todo", JSON.stringify(todo));
var para = document.createElement("div");
para.id = `deleteDiv${todo.length-1}`
console.log(para);
para.innerHTML = `<p>${todo[todo.length-1]}</p>
<button type="button" id = "deleteToDo${todo.length-1}">X</button>`
document.getElementById("updToDo").appendChild(para);
document.getElementById(`deleteToDo${todo.length-1}`).onclick = () => {
var elem = document.querySelector(`#deleteDiv${todo.length-1}`);
elem.parentNode.removeChild(elem);
deletedToDos.push(todo.length-1);
localStorage.setItem("deletedToDos", JSON.stringify(deletedToDos));
}
}