forked from academicpages/academicpages.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.js
23 lines (21 loc) · 853 Bytes
/
filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
document.addEventListener('DOMContentLoaded', function() {
const filterButtons = document.querySelectorAll('.filter-btn');
const blogCards = document.querySelectorAll('.blog-card');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
const filter = button.getAttribute('data-filter');
blogCards.forEach(card => {
if (filter === 'all') {
card.style.display = 'block';
} else {
const categories = card.getAttribute('data-category').split(' ');
if (categories.includes(filter)) {
card.style.display = 'block';
} else {
card.style.display = 'none';
}
}
});
});
});
});