Fix support for hashes that start with numbers

QuerySelector does not work with ids that start with numbers:

https://stackoverflow.com/questions/20306204/using-queryselector-with-ids-that-are-numbers
https://github.com/madrobby/zepto/issues/1333
This commit is contained in:
Yuxin Wu 2022-09-15 22:34:24 -07:00 committed by GitHub
parent 3456f8fd20
commit b44cf71d80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -52,7 +52,8 @@
// jump to location.hash
if (window.location.hash) {
setTimeout(() => {
document.querySelector(window.location.hash).scrollIntoView({ behavior: 'smooth' });
// Use getElementById because querySelector does not support ids that start with numbers
document.getElementById(window.location.hash.substring(1)).scrollIntoView({ behavior: 'smooth' });
}, i * 100);
}
});