19 lines
747 B
JavaScript
19 lines
747 B
JavaScript
document.addEventListener('DOMContentLoaded', function() {
|
|
const dropdownContainer = document.body; // or a more specific parent element
|
|
|
|
dropdownContainer.addEventListener('click', (event) => {
|
|
const button = event.target.closest('.dropdown-button');
|
|
if (button) {
|
|
const menu = button.nextElementSibling;
|
|
menu.classList.toggle('hidden');
|
|
event.stopPropagation(); // Prevent the click event from bubbling up
|
|
} else {
|
|
// Close all dropdowns if clicking outside
|
|
const dropdowns = document.querySelectorAll('.dropdown-menu');
|
|
dropdowns.forEach(dropdown => {
|
|
dropdown.classList.add('hidden');
|
|
});
|
|
}
|
|
});
|
|
});
|