-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathto-do-list.html
More file actions
119 lines (106 loc) · 4.51 KB
/
to-do-list.html
File metadata and controls
119 lines (106 loc) · 4.51 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>To Do List</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
</head>
<body>
<div class="container">
<header class="text-center my-4">
<h1>To-Do List</h1>
</header>
<main class="row">
<section class="border border-lg-none p-4 col-lg-4">
<form id="to-do-form">
<h3><label class="form-label" for="to-do">Enter to-do:</label></h3>
<input class="form-control" type="text" name="to-do" id="to-do">
<div class="d-grid">
<button class="btn btn-secondary mt-3 add">Add To-Do</button>
</div>
</form>
</section>
<section class="my-4 my-lg-0 col-lg-8">
<h3>To-Dos:</h3>
<ul class="list-group" id="to-do-list">
</ul>
</section>
</main>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
crossorigin="anonymous"></script>
<script>
// const toDoList = document.querySelector('#to-do-list');
// const formInput = document.querySelector("input[type='text']");
// const listItem = document.createElement("li");
// const listP = document.createElement("p");
// const listBtn = document.createElement("button")
// const toDoForm = document.querySelector('#to-do-form').appendChild(listItem);
// const theListItems = (event) => {
// event.preventDefault();
// listP.classList.add("m-0");
// listP.innerHTML = formInput.value;
// listItem.classList.add("to-do-item", "list-group-item", "d-flex", "justify-content-between", "align-items-center");
// listBtn.classList.add("btn", "btn-danger");
// listBtn.innerHTML = "Done";
// listItem.appendChild(listP);
// toDoList.appendChild(listItem);
// listP.appendChild(listBtn);
// formInput.value = '';
//
// }
//
// const eventButton = document.querySelectorAll(".btn-secondary");
//
// eventButton.forEach(button => button.addEventListener('click', theListItems));
// GET A REFERENCE TO THE FORM
// const form = document.getElementsByClassName("to-do-form");
// // ADD A TO-DO ITEM WHEN THE FORM IS SUBMITTED
// form.addEventListener("submit", event => {
// event.preventDefault();
// const todo = form.firstElementChild.nextElementSibling.value;
//
// const todoLi = document.createElement("li");
// todoLi.classList.add("to-do-item", "list-group-item", "d-flex", "justify-content-between", "align-items-center")
// todoLi.innerHTML = `<p>${todo}</p>` + `<button class="btn btn-danger">Remove</button>`
// document.getElementById("to-do-list").appendChild(todoLi)
//
// form.firstElementChild.nextElementSibling.value = "";
// })
//
// // DELETE A TO-DO ITEM WHEN THE REMOVE BUTTON IS CLICKED
//
// document.getElementById("to-do-list").addEventListener("click", event => {
// if (event.target.classList.contains("btn")) {
// // event.target.parentElement.remove();
// event.target.parentElement("");
//
// }
//
// })
const toDoList = document.querySelector('#to-do-list');
const formInput = document.querySelector("input[type='text']");
const formBtn = document.querySelector(".add");
formBtn.addEventListener('click', function (event) {
event.preventDefault();
const listItem = document.createElement("li");
listItem.classList.add("to-do-item", "list-group-item", "d-flex", "justify-content-between", "align-items-center");
const listP = document.createElement("p");
listP.classList.add("m-0");
listP.textContent = formInput.value;
const listBtn = document.createElement("button");
listBtn.classList.add("btn", "btn-danger");
listBtn.textContent = "Done";
listItem.appendChild(listP);
listItem.appendChild(listBtn);
toDoList.appendChild(listItem);
formInput.value = '';
listBtn.addEventListener('click', function () {
listItem.remove();
});
});
</script>
</body>
</html>