-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (60 loc) · 2.11 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function submit(){
const taskName = document.getElementById('taskInput_el').value;
if(taskName !== ''){
const newTask = {
task: taskName,
completed: false
}
localStorage.setItem(newTask.task,newTask.completed);
renderTasks();
}
}
function renderTasks(){
const tasklist = document.getElementById("taskList_el");
tasklist.innerHTML = '';
for (let i = 0; i < localStorage.length; i++){
const line = document.createElement("hr")
const taskName = document.createElement("p");
const taskItem = document.createElement("li");
const checkbox = document.createElement("input");
const deleteButton = document.createElement("button");
const deleteIcon = document.createElement("img")
deleteIcon.src= "delete_24dp_000000_FILL0_wght400_GRAD0_opsz24.png"
deleteButton.className = "deletebtn";
taskItem.className = "taskitem";
checkbox.type = "checkbox";
checkbox.className = "taskcbox";
const key = localStorage.key(i);
let status = JSON.parse(localStorage.getItem(key));
taskName.textContent = key;
console.log(status);
if(status !== false){
checkbox.checked = true;
// checkbox.className = "checked"
taskName.className = "disabled"
console.log("DISABLED!")
}
checkbox.addEventListener("change", ()=>{
if(status===false){
status = true;
}
else{
status =false;
}
localStorage.setItem(key, JSON.stringify(status));
renderTasks();
})
deleteButton.addEventListener("click",()=>{
line.remove();
taskItem.remove();
localStorage.removeItem(key)
})
deleteButton.appendChild(deleteIcon);
taskItem.appendChild(checkbox);
taskItem.appendChild(taskName);
taskItem.appendChild(deleteButton);
tasklist.appendChild(taskItem);
tasklist.appendChild(line);
}
}
renderTasks();