-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
26 lines (23 loc) · 1.11 KB
/
scripts.js
File metadata and controls
26 lines (23 loc) · 1.11 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
document.addEventListener('DOMContentLoaded', () => {
const dropdown = document.querySelector('.dropdown');
const dropbtn = document.querySelector('.dropbtn');
const searchInput = document.getElementById('search-input');
const dropdownLinks = document.querySelectorAll('.dropdown-content a');
dropdownLinks.forEach(link => {
link.addEventListener('click', (event) => {
event.preventDefault();
const selectedCategory = event.target.getAttribute('data-value');
dropbtn.textContent = selectedCategory;
searchInput.placeholder = `Searching in ${selectedCategory.toLowerCase()}...`;
});
});
document.addEventListener('click', (event) => {
if (!dropdown.contains(event.target)) {
document.querySelector('.dropdown-content').style.display = 'none';
}
});
dropbtn.addEventListener('click', () => {
const dropdownContent = document.querySelector('.dropdown-content');
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
});