-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (31 loc) · 1.29 KB
/
script.js
File metadata and controls
34 lines (31 loc) · 1.29 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
document.addEventListener("DOMContentLoaded", function () {
const termsContainer = document.getElementById("terms");
const searchBar = document.getElementById("searchBar");
fetch("terms.json")
.then(response => response.json())
.then(terms => {
// Sort terms alphabetically by term name
terms.sort((a, b) => a.term.localeCompare(b.term));
displayTerms(terms);
// Filter terms based on the search input (only by term name)
searchBar.addEventListener("input", () => {
const filteredTerms = terms.filter(term =>
term.term.toLowerCase().includes(searchBar.value.toLowerCase())
);
displayTerms(filteredTerms);
});
})
.catch(error => console.error("Error loading terms:", error));
function displayTerms(terms) {
termsContainer.innerHTML = ""; // Clear previous results
terms.forEach(term => {
const termElement = document.createElement("div");
termElement.classList.add("term-item");
termElement.innerHTML = `
<h2>${term.term}</h2>
<p>${term.description}</p>
`;
termsContainer.appendChild(termElement);
});
}
});