WordPress.org

Make WordPress Core

Changeset 52213


Ignore:
Timestamp:
11/19/2021 01:01:23 PM (13 days ago)
Author:
audrasjb
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js

    r51304 r52213  
    181181                setTimeout(function () {
    182182                    var anchor = document.getElementById(event.target.hash.slice(1));
    183                     anchor.scrollIntoView();
     183                    if ( anchor ) {
     184                        anchor.scrollIntoView();
     185                    }
    184186                }, 550);
    185187            }
Note: See TracChangeset for help on using the changeset viewer.