-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (47 loc) · 1.22 KB
/
script.js
File metadata and controls
48 lines (47 loc) · 1.22 KB
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
const inputBox = document.getElementById("inputBox");
const addBtn = document.getElementById("addBtn");
const listgroup = document.querySelector(".list-group");
const form = document.querySelector("form");
form.onsubmit = (e) => {
e.preventDefault();
};
function addTask() {
if (inputBox.value == "") {
alert("cant be empty");
} else {
let li = document.createElement("li");
li.classList.add("list-group-item");
li.innerHTML = inputBox.value;
listgroup.appendChild(li);
li.classList.add("list-group-item");
let span = document.createElement("span");
li.appendChild(span);
let hr = document.createElement("hr");
li.appendChild(hr);
let i = document.createElement("i");
i.innerHTML = "\u00d7";
li.appendChild(i);
saveData();
}
inputBox.value = "";
}
listgroup.addEventListener(
"click",
(e) => {
if (e.target.tagName === "LI") {
e.target.classList.toggle("checked");
saveData();
} else if (e.target.tagName === "I") {
e.target.parentElement.remove();
saveData();
}
},
false
);
saveData = () => {
localStorage.setItem("data", listgroup.innerHTML);
};
showTask = () => {
listgroup.innerHTML = localStorage.getItem("data");
};
showTask();