Skip to content

Commit b9efa4d

Browse files
committed
added persistent storage
1 parent d23cbf6 commit b9efa4d

File tree

3 files changed

+93
-110
lines changed

3 files changed

+93
-110
lines changed

ToDoList/aditya7302/index.html

Lines changed: 93 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,105 @@
1+
copied
2+
13
<!DOCTYPE html>
24
<html lang="en">
35

46
<head>
57
<meta charset="UTF-8">
68
<meta http-equiv="X-UA-Compatible" content="IE=edge">
79
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8-
<title>Document</title>
9-
<link rel="stylesheet" href="styles.css">
10+
<title>Todo App</title>
11+
<style>
12+
* {
13+
margin: 0;
14+
padding: 0;
15+
box-sizing: border-box;
16+
}
17+
18+
body {
19+
display: flex;
20+
align-items: center;
21+
justify-content: center;
22+
flex-direction: column;
23+
}
24+
25+
form {
26+
width: 80%;
27+
}
28+
29+
form * {
30+
width: 100%;
31+
height: 20px;
32+
margin-top: 2px;
33+
}
34+
35+
table {
36+
width: 80%;
37+
}
38+
39+
th,
40+
td {
41+
border: 1px solid #000;
42+
}
43+
44+
h1 {
45+
color: brown;
46+
}
47+
48+
td[onclick] {
49+
background-color: red;
50+
color: #fff;
51+
border-radius: 5px;
52+
cursor: pointer;
53+
text-align: center;
54+
}
55+
</style>
1056
</head>
1157

1258
<body>
13-
<main>
14-
<div class="box">
15-
<input type="text" id="item" autofocus placeholder="Write something here...">
16-
<ul id="to-do-box">
17-
</ul>
18-
</div>
19-
</main>
20-
<script src="https://kit.fontawesome.com/bf520e6492.js" crossorigin="anonymous"></script>
21-
<script src="script.js"></script>
59+
<h1>Todo App</h1>
60+
<form>
61+
<input type="text" required>
62+
<input type="submit">
63+
</form>
64+
<table>
65+
<thead>
66+
<tr>
67+
<th>Todo's</th>
68+
<th>Delete</th>
69+
</tr>
70+
</thead>
71+
<tbody></tbody>
72+
</table>
73+
<script>
74+
// ["gfgf","hggbhd"]
75+
let form = document.querySelector("form");
76+
let ls = localStorage.getItem('todo');
77+
let todo = ls ? JSON.parse(ls) : [];
78+
form.addEventListener('submit', (e) => {
79+
e.preventDefault();
80+
let inpData = form[0].value;
81+
todo.push(inpData)
82+
localStorage.setItem('todo', JSON.stringify(todo))
83+
location.reload()
84+
})
85+
todo.map((data, index) => {
86+
document.querySelector("tbody").innerHTML += `
87+
<tr>
88+
<td>${data}</td>
89+
<td onclick="del(${index})">Delete</td>
90+
</tr>
91+
`;
92+
})
93+
94+
function del(e) {
95+
let deleted = todo.filter((data, index) => {
96+
return index !== e;
97+
})
98+
localStorage.setItem('todo', JSON.stringify(deleted))
99+
location.reload()
100+
}
101+
</script>
22102
</body>
23103

24-
</html>
104+
</html>
105+

ToDoList/aditya7302/script.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

ToDoList/aditya7302/styles.css

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)