-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathEvan.js
44 lines (38 loc) · 1.2 KB
/
Evan.js
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
import { DOMSelectors } from "./dom.js";
import "../css/style.css";
const ToDoItems = [];
function addToDo(event) {
DOMSelectors.toDoList.innerHTML = "";
const inputtedToDo = DOMSelectors.userInput.value;
event.preventDefault();
ToDoItems.push(inputtedToDo);
displayToDoList(ToDoItems);
DOMSelectors.userInput.value = "";
}
function displayToDoList(array) {
array.forEach((inputs) => {
DOMSelectors.toDoList.insertAdjacentHTML(
"beforeend",
`<div class="card"><div class = "to-do-card">${inputs}</div>
<button type ="submit" class="remove-button" id="remove-reminder"> Remove </button>
</div>`
);
});
const removeButton = document.querySelectorAll(".remove-button");
removeButton.forEach((button) => {
button.addEventListener("click", removeToDo);
});
function removeToDo() {
const specificCard = this.parentElement;
const specificCardText =
specificCard.querySelector(".to-do-card").textContent;
for (let i = 0; i < ToDoItems.length; i++) {
if (ToDoItems[i] === specificCardText) {
ToDoItems.splice(i, 1);
break;
}
}
specificCard.remove();
}
}
DOMSelectors.submitButton.addEventListener("click", addToDo);