Skip to content

Commit 9713feb

Browse files
committed
add js and complete To Do list Function
1 parent 955317e commit 9713feb

File tree

4 files changed

+135
-4
lines changed

4 files changed

+135
-4
lines changed
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
@media (max-width: 768px) {
1+
@media (max-width: 920px) {
22
div.container {
33
width: 90%;
44
}
5+
6+
div.container h1 {
7+
font-size: 1.5rem;
8+
}
9+
10+
div.container div.form-area {
11+
flex-flow: column wrap;
12+
gap: 0px;
13+
}
514
}

Mini ToDoList App Page/css/style.css

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ html {
2222

2323
body {
2424
font-family: var(--primary-font), sans-serif;
25+
text-transform: capitalize;
2526
background-color: var(--white-color);
2627
height: 100vh;
2728
display: flex;
@@ -38,6 +39,33 @@ body {
3839
box-sizing: border-box;
3940
}
4041

42+
ul {
43+
list-style-type: none;
44+
}
45+
46+
ol#to-do-list {
47+
width: 80%;
48+
font-family: inherit;
49+
list-style-position: inside;
50+
}
51+
52+
ol#to-do-list li {
53+
width: 100%;
54+
height: 30px;
55+
line-height: 30px;
56+
background-color: var(--dark-color);
57+
color: var(--secondary-color);
58+
border-radius: var(--default-radius);
59+
padding: 0 15px;
60+
margin: 15px auto;
61+
cursor: pointer;
62+
}
63+
64+
ol#to-do-list li:hover {
65+
background-color: var(--secondary-color);
66+
color: var(--dark-color);
67+
}
68+
4169
img {
4270
width: 100%;
4371
}
@@ -55,6 +83,13 @@ button {
5583
}
5684

5785
/* PublicItems */
86+
hr {
87+
background-color: var(--dark-color);
88+
height: 0.4rem;
89+
border-radius: var(--default-radius);
90+
width: 80%;
91+
margin: 15px auto;
92+
}
5893
button a.button {
5994
display: block;
6095
padding: 1rem 3.5rem;
@@ -104,5 +139,53 @@ div.container {
104139
background-color: white;
105140
border-radius: var(--default-radius);
106141
box-shadow: 3px 6px 10px 3px rgba(0, 0, 0, 0.15);
142+
display: flex;
143+
flex-flow: column nowrap;
144+
justify-content: flex-start;
145+
align-items: center;
146+
gap: 1rem;
147+
overflow-y: auto;
148+
}
149+
150+
div.container h1 {
151+
color: var(--dark-color);
152+
text-align: center;
153+
margin: 15px;
154+
}
155+
156+
div.container h1::first-letter {
157+
color: var(--primary-color);
158+
}
159+
160+
div.container h1 + em {
161+
display: block;
162+
text-align: center;
163+
color: var(--dark-color);
164+
}
165+
166+
div.container h1 + em::first-letter {
167+
color: var(--primary-color);
168+
}
169+
170+
div.container div.form-area {
171+
display: flex;
172+
flex-flow: row nowrap;
173+
justify-content: center;
174+
align-items: center;
175+
gap: 0.3rem;
176+
}
177+
178+
div.container div.form-area input[type="text"]#input {
179+
background-color: var(--dark-color);
180+
padding: 1rem 3.5rem;
181+
margin: 1rem auto;
182+
border-radius: var(--default-radius);
183+
font-size: 18px;
184+
color: var(--secondary-color);
185+
}
186+
187+
div.container div.form-area input[type="text"]#input::placeholder {
188+
color: var(--secondary-color);
189+
opacity: 0.5;
107190
}
108191
/* End Of Body */

Mini ToDoList App Page/index.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,17 @@
4747
<title>Mini ToDoList App Page</title>
4848
</head>
4949
<body>
50-
<div class="container"></div>
51-
<button><a href="#" class="button">Test Button</a></button>
50+
<div class="container">
51+
<h1>Simple JS To Do List For You</h1>
52+
<em>Double Click To Remove A Task</em>
53+
<hr />
54+
<div class="form-area">
55+
<input type="text" placeholder="New Task..." id="input" />
56+
<button id="button"><a href="#" class="button">Test Button</a></button>
57+
</div>
58+
<ol type="1" id="to-do-list"></ol>
59+
</div>
60+
5261
<div id="root"></div>
5362
<script src="./js/main.js"></script>
5463
</body>

Mini ToDoList App Page/js/main.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
document.addEventListener("DOMContentLoaded", function () {});
1+
document.addEventListener("DOMContentLoaded", function () {
2+
const taskLists = [];
3+
const listItems = document.getElementById("to-do-list");
4+
const input = document.querySelector("input[type='text']");
5+
const button = document.getElementById("button");
6+
7+
button.addEventListener("click", function () {
8+
const inputValue = input.value.trim();
9+
if (!inputValue) return;
10+
11+
taskLists.push(inputValue);
12+
input.value = "";
13+
14+
// Clear existing list
15+
listItems.innerHTML = "";
16+
17+
// Loop through taskLists and create <li> for each
18+
taskLists.forEach((task, index) => {
19+
const li = document.createElement("li");
20+
li.textContent = task;
21+
22+
// Add double-click to remove
23+
li.addEventListener("dblclick", function () {
24+
taskLists.splice(index, 1); // Remove from array
25+
listItems.removeChild(li); // Remove from DOM
26+
});
27+
28+
listItems.appendChild(li);
29+
});
30+
});
31+
});

0 commit comments

Comments
 (0)