-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
85 lines (63 loc) · 2.11 KB
/
index.html
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
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To Do App</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<h1><u>To-Do App</u></h1>
<div class="input-container">
<input type="text" id="task-input" placeholder="Enter a new task" class="task-input">
<button onclick="addTask()" class="action-btn">Add Task</button>
</div>
<div id="tasks-container" class="list-container">
</div>
<script>
const tasks = [""];
function loadFromLocalStorage() {
const allTasks = JSON.parse(localStorage.getItem('allTasks'));
if (allTasks) {
tasks.length = 0;
tasks.push(...allTasks);
}
loadTasks();
}
function loadTasks() {
localStorage.setItem('allTasks', JSON.stringify(tasks));
const tasksContainer = document.getElementById("tasks-container");
tasksContainer.innerHTML = '';
for (const task of tasks) {
tasksContainer.innerHTML += `
<div class="todo-item">
${task}
<div class="del-btn" type="button" onclick="deleteTask('${task}')">
<img src="./img/delete-img.png" class="del-img">
</div>
</div>
`
}
}
function addTask() {
const inputElement = document.getElementById("task-input");
const newTask = inputElement.value;
document.getElementById("task-input").value='';
if (!newTask) {
alert('Please Enter Task');
return;
}
tasks.push(newTask);
loadTasks();
}
function clearInput(){
}
function deleteTask(task) {
const taskIndex = tasks.indexOf(task);
tasks.splice(taskIndex, 1);
loadTasks();
}
loadFromLocalStorage();
</script>
</body>
</html>