diff --git a/src/js/scripts.js b/src/js/scripts.js index 0788fdd..33fdd4a 100644 --- a/src/js/scripts.js +++ b/src/js/scripts.js @@ -44,6 +44,17 @@ document.addEventListener('DOMContentLoaded', () => // Update nav links and add anchor links to section headers. sectionsWithId.forEach(anchorTarget => { + // Navigate within current page if a section for the anchor exists. + navLinks.forEach(navLink => + { + const href = navLink.getAttribute('href'); + + if (href.startsWith('/#') && href.substring(2) === anchorTarget.id) + { + navLink.setAttribute('href', href.substring(1)); + } + }); + /** * @type {HTMLHeadingElement|null} */