function generateHeaderAndFooter() { // Add the header and footer HTML as you've done in your dynamic script const header = document.getElementById('header-placeholder'); const footer = document.getElementById('footer-placeholder'); header.innerHTML = ` `; // Add the footer HTML footer.innerHTML = ` `; const mobileMenuToggle = document.getElementById('mobile-menu-toggle'); const mobileMenu = document.getElementById('mobile-menu'); const searchButton = document.getElementById('mobile-search-button'); // Close mobile menu on search button click searchButton.addEventListener('click', function() { if (mobileMenu.style.display === "block") { mobileMenu.style.display = "none"; // Close the mobile menu } }); // Toggle mobile menu visibility on menu button click mobileMenuToggle.addEventListener('click', function() { if (mobileMenu.style.display === "none" || mobileMenu.style.display === "") { mobileMenu.style.display = "block"; // Open the mobile menu } else { mobileMenu.style.display = "none"; // Close the mobile menu } }); // Optional: If you want the mobile menu to close on clicking any menu item const menuItems = document.querySelectorAll('#mobile-menu a'); menuItems.forEach(item => { item.addEventListener('click', function() { mobileMenu.style.display = "none"; // Close the mobile menu when an item is clicked }); }); // Function to handle the resize and hide the mobile menu on desktop function handleResize() { if (window.innerWidth >= 768) { mobileMenu.classList.add('hidden'); // Hide the mobile menu on desktop mobileMenu.style.display = "none"; // Ensure it's closed when resizing to desktop } else { mobileMenu.classList.remove('hidden'); // Show the mobile menu on mobile } } // Initialize and listen for window resizing handleResize(); window.addEventListener('resize', handleResize); };