-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (28 loc) · 1.07 KB
/
index.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
"use strict";
const entryForm = document.getElementById("entryForm");
const entriesSection = document.querySelector("#entries");
const entryTextbox = document.querySelector(".entry-textbox");
const entriesNav = document.querySelector(".entries-nav");
let count = 1;
function addEntryToDiary(event) {
event.preventDefault();
const entryDiv = document.createElement("div");
entryDiv.className = "single-entry";
entryDiv.innerText = entryTextbox.value;
entryDiv.style.display = "none";
entriesSection.appendChild(entryDiv);
entryTextbox.value = "";
const displayEntryBtn = document.createElement("button");
displayEntryBtn.className = "display-entry-button";
displayEntryBtn.innerText = count;
entriesNav.appendChild(displayEntryBtn);
displayEntryBtn.addEventListener("click", function () {
const allEntries = document.querySelectorAll(".single-entry");
for (let i = 0; i < allEntries.length; i++) {
allEntries[i].style.display = "none";
}
entryDiv.style.display = "block";
});
count++;
}
entryForm.addEventListener("submit", addEntryToDiary);