forked from NageshMandal/Engineering-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.js
More file actions
26 lines (22 loc) · 730 Bytes
/
library.js
File metadata and controls
26 lines (22 loc) · 730 Bytes
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
// Event listener for branch selection
const branchSelect = document.getElementById('branch');
branchSelect.addEventListener('change', function() {
const selectedBranch = branchSelect.value;
filterBooksByBranch(selectedBranch);
});
// Function to filter books by branch
function filterBooksByBranch(branch) {
const bookList = document.getElementById('bookList');
const books = bookList.getElementsByTagName('div');
for (let i = 0; i < books.length; i++) {
const book = books[i];
const bookBranch = book.dataset.branch;
if (branch === '' || branch === bookBranch) {
book.style.display = 'block';
} else {
book.style.display = 'none';
}
}
}
// Initial filter
filterBooksByBranch('');