Skip to content

Commit 6039a7a

Browse files
script.js
1 parent 85c33cf commit 6039a7a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Diff for: script.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const inputBox = document.getElementById("input-box");
2+
const listContainer = document.getElementById("list-container");
3+
4+
function addTask() {
5+
if (inputBox.value === '') {
6+
alert("You must write some Task!");
7+
} else {
8+
let li = document.createElement("li");
9+
li.innerHTML = inputBox.value;
10+
listContainer.appendChild(li);
11+
12+
let span = document.createElement("span");
13+
span.innerHTML = "\u00d7";
14+
span.classList.add("close");
15+
li.appendChild(span);
16+
}
17+
inputBox.value = "";
18+
saveData();
19+
}
20+
21+
listContainer.addEventListener("click", function (e) {
22+
if (e.target.tagName === "LI") {
23+
e.target.classList.toggle("checked");
24+
saveData();
25+
} else if (e.target.tagName === "SPAN") {
26+
e.target.parentElement.remove();
27+
saveData();
28+
}
29+
}, false);
30+
31+
function saveData() {
32+
localStorage.setItem("tasks", listContainer.innerHTML);
33+
}
34+
35+
function loadTasks() {
36+
listContainer.innerHTML = localStorage.getItem("tasks");
37+
}
38+
39+
loadTasks();

0 commit comments

Comments
 (0)