-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
31 lines (29 loc) · 1.25 KB
/
script.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
document.addEventListener("DOMContentLoaded", () => {
const collapsibles = document.querySelectorAll(".collapsible");
collapsibles.forEach((collapsible) => {
collapsible.addEventListener("click", () => {
const content = collapsible.nextElementSibling;
content.style.display = content.style.display === "block" ? "none" : "block";
});
});
const searchBar = document.getElementById("search-bar");
searchBar.addEventListener("input", () => {
const searchQuery = searchBar.value.toLowerCase();
const sections = document.querySelectorAll("section");
sections.forEach((section) => {
const links = section.querySelectorAll("a");
let sectionVisible = false;
links.forEach((link) => {
const linkText = link.textContent.toLowerCase();
if (linkText.includes(searchQuery)) {
link.style.display = "block";
sectionVisible = true;
} else {
link.style.display = "none";
}
});
// Show or hide the section based on search results
section.style.display = sectionVisible ? "block" : "none";
});
});
});