-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathscript.js
More file actions
57 lines (46 loc) · 1.6 KB
/
script.js
File metadata and controls
57 lines (46 loc) · 1.6 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
// toggle hamburger menu (for mobile devices)
function toggleMenu() {
var navLinks = document.querySelector(".nav-links");
var hamburgerIcon = document.getElementById("hamburger-icon");
var xIcon = document.getElementById("x-icon");
// add/remove class from navLinks
navLinks.classList.toggle("active");
// specify the display of hamburgerIcon and xIcon
if (document.querySelector(".nav-links").classList.contains("active")) {
hamburgerIcon.style.display = "none";
xIcon.style.display = "block";
} else {
hamburgerIcon.style.display = "block";
xIcon.style.display = "none";
}
}
// scroll to top when clicking the logo
document.querySelector(".logo-content").addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth"
})
})
// Check for element click to close the navigation bar
document.querySelectorAll(".nav-links a").forEach(link => {
link.addEventListener("click", () => {
toggleMenu()
})
})
// Select all paragraphs inside .qa-card and initially hide them
// Select all question headers
const questions = document.querySelectorAll(".question");
questions.forEach(question => {
question.addEventListener("click", () => {
// Get the parent .qa-card of the clicked question
const parentCard = question.closest(".qa-card");
// Find the <p> inside the same .qa-card
const paragraph = parentCard.querySelector("p");
// Toggle paragraph visibility
if (paragraph.style.display === "none" || paragraph.style.display == '') {
paragraph.style.display = "block";
} else {
paragraph.style.display = "none";
}
});
});