jQuery(function ($) { // Getting links from a page and turning them into a scroll-spy bespoke menu // FIXME when page loads with #... in url, the scroll spy gets messed up. let links; links = document.querySelectorAll("#one, #two, #three") let url = window.location.href; let innerContent = ""; links.forEach(link => { let fullUrl = url + "#" + link.id; innerContent += "
  • " + link.attributes.name.value + "
  • " }); console.log(innerContent) let menu; menu = document.getElementById("menu-test-scroll-spy"); menu.innerHTML = innerContent // Activate Scrollspy $('.entry-content').scrollspy({ target: '#nav_menu-4' }); // Refresh Scrollspy $('[data-spy="scroll"]').each(function () { $(this).scrollspy("refresh"); }); });