Last active
January 18, 2023 12:04
-
-
Save sunny/481146 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Change window.location.hash without scrolling the page, even in IE | |
// by renaming the element's id temporarily | |
function changeHashWithoutScrolling(hash) { | |
const id = hash.replace(/^.*#/, '') | |
const elem = document.getElementById(id) | |
elem.id = `${id}-tmp` | |
window.location.hash = hash | |
elem.id = id | |
} |
change getElementBy to getElementById
Woops. Thanks for the heads-up, it’s now updated.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Glad it could help! I've just updated the code to use ES6.