-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtdl-script.js
45 lines (38 loc) · 1.16 KB
/
tdl-script.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
const taskInput = document.getElementById("task-input");
const taskForm = document.getElementById("task-form");
const taskList = document.getElementById("task-list");
taskForm.addEventListener("submit", (e) => {
e.preventDefault();
const taskTitle = taskInput.value;
console.log(taskTitle);
if (taskTitle == "") {
alert("Please Enter valid Task");
} else {
const listItem = document.createElement("li");
listItem.innerHTML = taskTitle;
taskList.append(listItem);
let span = document.createElement("span");
span.innerHTML = `×`;
listItem.appendChild(span);
taskInput.value = "";
saveListData();
}
});
taskList.addEventListener("click", (e) => {
if (e.target.tagName == "LI") {
e.target.classList.toggle("checked");
saveListData();
}
if (e.target.tagName == "SPAN") {
const li = e.target.parentElement;
li.remove();
saveListData();
}
});
function showListData() {
taskList.innerHTML = localStorage.getItem("listItem");
}
function saveListData() {
localStorage.setItem("listItem", taskList.innerHTML);
}
showListData();