-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (25 loc) · 1.27 KB
/
Copy pathscript.js
File metadata and controls
30 lines (25 loc) · 1.27 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
document.addEventListener('DOMContentLoaded', () => {
const searchInput = document.getElementById('searchInput');
const categoryFilter = document.getElementById('categoryFilter');
const elements = document.querySelectorAll('.element');
function filterElements() {
const searchTerm = searchInput.value.toLowerCase();
const selectedCategory = categoryFilter.value;
elements.forEach(element => {
const name = element.dataset.name.toLowerCase();
const symbol = element.querySelector('.symbol').textContent.toLowerCase();
const category = element.dataset.category;
// Check if element matches search AND category
const matchesSearch = name.includes(searchTerm) || symbol.includes(searchTerm);
const matchesCategory = selectedCategory === 'all' || category === selectedCategory;
if (matchesSearch && matchesCategory) {
element.classList.remove('faded');
} else {
element.classList.add('faded');
}
});
}
// Add event listeners to trigger filtering when the user types or selects
searchInput.addEventListener('input', filterElements);
categoryFilter.addEventListener('change', filterElements);
});