document.addEventListener("DOMContentLoaded", function () { const menuItems = document.querySelectorAll(".menu-item"); menuItems.forEach((item) => { // Handle Hover for Desktop item.addEventListener("mouseenter", function () { if (window.innerWidth > 768) { const subMenu = this.querySelector(".sub-menu"); if (subMenu) subMenu.style.display = "block"; } }); item.addEventListener("mouseleave", function () { if (window.innerWidth > 768) { const subMenu = this.querySelector(".sub-menu"); if (subMenu) subMenu.style.display = "none"; } }); // Handle Click for Mobile item.addEventListener("click", function (e) { if (window.innerWidth <= 768) { e.preventDefault(); const subMenu = this.querySelector(".sub-menu"); if (subMenu) { const isOpen = subMenu.style.display === "block"; document.querySelectorAll(".sub-menu").forEach((menu) => { menu.style.display = "none"; // Close all other menus }); subMenu.style.display = isOpen ? "none" : "block"; } } }); }); });