-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.js
25 lines (23 loc) · 959 Bytes
/
new.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
document.addEventListener('DOMContentLoaded', function() {
var dropdownToggle = document.getElementById('navbarDropdown');
var dropdownMenu = document.getElementById('dropdownMenu');
// Toggle dropdown menu on click
dropdownToggle.addEventListener('click', function(e) {
e.preventDefault();
var isMenuVisible = dropdownMenu.style.display === 'block';
// Hide all dropdowns first
document.querySelectorAll('.dropdown-menu').forEach(function(menu) {
menu.style.display = 'none';
});
// Show the clicked one
if (!isMenuVisible) {
dropdownMenu.style.display = 'block';
}
});
// Hide dropdown when clicking outside
document.addEventListener('click', function(e) {
if (!dropdownToggle.contains(e.target) && !dropdownMenu.contains(e.target)) {
dropdownMenu.style.display = 'none';
}
});
});