const hamburgerLink = document.querySelectorAll( ".navlinks .group .sub a" ); hamburgerLink.forEach((item) => { item.addEventListener("click", (e) => { e.preventDefault(); let section = document.querySelector(item.getAttribute("href")); if (section) { window.location.hash = `${item.getAttribute("href")}`; // inject hash into url section.scrollIntoView({ behavior: "smooth", }); } else { window.location.replace("/" + item.getAttribute("href")); // just redirect if ever section is not found based on the id } toggleNav.click(); }); });