$( document ).ready(function() { function scrollToHash(hash) { if (hash.length > 0) { $('html, body').animate({ scrollTop: $(`#${hash}`).offset().top }, 500); } } $('#content h2').each(function(index) { var title = $(this).text(); var id = $(this).attr("id"); // inject headers into user journeys table-of-contents (buttons) $("#user-journeys-toc").append(`
${index + 1}. ${title}
`) // replace content headers with styled banners $(this).replaceWith(`


${index + 1}
  ${title}
`) }); $('div#user-journeys-toc a').each(function() { $(this).click(function() { var target = $(this).attr("href").replace("#", ""); scrollToHash(target); }); }); // jump to section in URL now that anchors are created scrollToHash(window.location.hash.substr(1)); });