From e920b646c017707cbcfe87d20b9f58c8e2526e21 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 13 Aug 2020 20:13:21 +0100 Subject: [PATCH] Target all anchor links and only scroll when target exists --- static/src/js/app.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/static/src/js/app.js b/static/src/js/app.js index 4989903..ca4a14d 100644 --- a/static/src/js/app.js +++ b/static/src/js/app.js @@ -77,10 +77,12 @@ $('#scroll-top').on('click', function(event) { scrollTo(0); }); -$('#TableOfContents a').on('click', function(event) { +$('a[href^="#"] ').on('click', function(event) { event.preventDefault(); const target = $($(this).attr('href')); - scrollTo(target.offset().top); + if (target.length) { + scrollTo(target.offset().top); + } }); $('[data-clipboard-text]').on('click', function(event) {