Skip to content

Commit 33f73b2

Browse files
authored
Merge pull request #860 from aditya7302/master
added todo list app
2 parents 4d94510 + d7d2c81 commit 33f73b2

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

ToDoList/aditya7302/index.html

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
copied
2+
3+
<!DOCTYPE html>
4+
<html lang="en">
5+
6+
<head>
7+
<meta charset="UTF-8">
8+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
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>
56+
</head>
57+
58+
<body>
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>
102+
</body>
103+
104+
</html>
105+

0 commit comments

Comments
 (0)