// Function to set the active link function setActiveLink(activeElement) { // Remove the 'active' class from all links // var links = document.querySelectorAll('.nav a'); var links = document.querySelectorAll('a'); links.forEach(function(link) { link.classList.remove('active'); }); // Add the 'active' class to the clicked link activeElement.classList.add('active'); } // Get the current page's filename const currentPage = window.location.pathname.split("/").pop(); // Map page names to the corresponding nav link IDs const navLinks = { 'intro.php': 'loadIntro', 'products.php': 'loadProducts', 'story.php': 'loadStory', 'users.php': 'loadUsers', 'benefits.php': 'loadBenefits' }; // Add the 'active' class to the current page's link if (navLinks[currentPage]) { document.getElementById(navLinks[currentPage]).classList.add('active'); } // Debugging: Output the current page and corresponding link ID to the console console.log("Current Page:", currentPage); console.log("Link ID:", navLinks[currentPage]); // Check if the current page exists in the navLinks object if (navLinks[currentPage]) { const linkElement = document.getElementById(navLinks[currentPage]); // Additional check to ensure the element exists before applying the class if (linkElement) { linkElement.classList.add('active'); } else { console.error("No element found for ID:", navLinks[currentPage]); } } else { console.error("No matching link for current page:", currentPage); } --------- links.forEach(function(link) { console.log(link); // This will show you the link or undefined in the console if (link && link.classList) { link.classList.remove('active'); } });