From 48fe42e9d211839f23fbe791a5eecfc1f66aad15 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Fri, 19 Nov 2021 13:01:23 +0000 Subject: [PATCH] Twenty Twenty-One: Check if anchor exists before triggering in-page navigation. This prevents JavaScript errors when using hash in URLs without matching them to any existing anchor in the page. Props rixeo, sabernhardt, pbearne. Fixes #53619. git-svn-id: https://develop.svn.wordpress.org/trunk@52213 602fd350-edb4-49c9-b593-d223f7449a82 --- .../themes/twentytwentyone/assets/js/primary-navigation.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js b/src/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js index 4c88190f12..ec15e106dc 100644 --- a/src/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js +++ b/src/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js @@ -180,7 +180,9 @@ function twentytwentyoneExpandSubMenu( el ) { // jshint ignore:line // Wait 550 and scroll to the anchor. setTimeout(function () { var anchor = document.getElementById(event.target.hash.slice(1)); - anchor.scrollIntoView(); + if ( anchor ) { + anchor.scrollIntoView(); + } }, 550); } } );