function dynamicVetIsNav(){ const vetisMainNavLinks = document.querySelectorAll('#vetis-main-navigation .vet-nav__menu-link'); const currentURL = window.location.pathname; const pathSegments = currentURL.split('/').filter(segment => segment !== ""); if(vetisMainNavLinks){ if (pathSegments.length >= 3) { const vetisMainURLPathname = pathSegments.slice(0, 3).join('/'); for (const navLink of vetisMainNavLinks){ const navhref = navLink.getAttribute("href"); if (navhref.includes(vetisMainURLPathname)) navLink.classList.add("active"); } } } } document.addEventListener("DOMContentLoaded", dynamicVetIsNav);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter