Repository navigation
Expand file tree
/
Copy pathtodo_list.html
More file actions
97 lines (75 loc) 路 2.61 KB
/
Copy pathtodo_list.html
File metadata and controls
97 lines (75 loc) 路 2.61 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<head>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>ToDo List</title>
<style>
body {
text-align: center;
font-family: 'Josefin Sans', sans-serif;
}
h1 {
margin-top: 10px;
margin-bottom: 30px;
font-size: 5em;
}
li {
list-style: none;
}
.newBtn {
margin: 10px;
background-color: #dc3545;
}
.done {
text-decoration: line-through;
}
#reload {
margin: 25px;
}
</style>
</head>
<body>
<h1>ToDo List</h1>
<form action="/nowhere">
<input type="text" id="product" name="product" placeholder="enter item">
<button disabled id="btn-submit">Submit</button>
</form>
<br><br>
<h3>List:</h3>
<ul id="list"></ul>
<button id="reload" onclick="location.reload()">Refresh</button>
<!-- ------------------------------------------------------------- -->
<!-- ------------------------------------------------------------- -->
<script>
let form = document.querySelector('form');
let product = document.getElementById("product");
let buttonSubmit = document.getElementById("btn-submit")
product.addEventListener('keyup', (event) => {
let value = event.target.value;
value !== '' ? buttonSubmit.disabled = false : buttonSubmit.disabled = true
});
form.addEventListener("submit", (event) => {
let li = document.createElement("li");
let btn = document.createElement("button");
let span = document.createElement("span");
btn.innerText = "Delete Item";
btn.classList.add("newBtn");
li.append(product.value, btn);
li.addEventListener('click', () => {
li.classList.toggle('done');
});
span.append(li);
let ul = document.querySelector("#list");
ul.append(span);
btn.addEventListener("click", () => {
span.remove();
})
product.value = "";
buttonSubmit.disabled = true;
event.preventDefault();
});
</script>
</body>
</html>