-
Notifications
You must be signed in to change notification settings - Fork 0
/
p_blog.js
32 lines (28 loc) · 1.23 KB
/
p_blog.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
32
document.addEventListener('DOMContentLoaded', () => {
const filterButtons = document.querySelectorAll('.filter-button');
const posts = document.querySelectorAll('.one-post');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove 'active' class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add 'active' class to the clicked button
button.classList.add('active');
const filter = button.getAttribute('data-filter');
posts.forEach(post => {
if (filter === 'all') {
post.style.visibility = 'visible';
post.style.position = 'relative';
} else {
const field = post.getAttribute('data-field');
if (field === filter) {
post.style.visibility = 'visible';
post.style.position = 'relative';
} else {
post.style.visibility = 'hidden';
post.style.position = 'absolute';
}
}
});
});
});
});