-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
css :target selector does not work when loading a new page #143
Comments
AFAIK it's a known bug that most browser implementations don't update This cannot be fixed by Unpoly I'm afraid. A workaround would be to assign a class :target, .hash-target {
background-color: yellow
} You could assign that let markedElement = null
window.addEventListener('hashchange', function() {
if (markedElement) {
markedElement.classList.remove('hash-target')
}
if (location.hash && (markedElement = document.querySelector(location.hash))) {
markedElement.classList.add('hash-target')
}
}); |
I ended up solving this differently for our documentation site unpoly.com, see commit linked above. |
Thanks for the update, I will take a look. |
I am utilizing the css :target selector for highlighting anchor tags that I jump to on a page. It works fine jumping to an element on the same page, but if I navigate to a new page with an anchor tag it does not trigger the :target selector properly.
Example:
Current page: /stuff
This triggers :target selector as expected: /stuff#thing1
This does not trigger the :target selector: /more#thing1
As is, the only workaround I have is to remove Unpoly functionality from links where I'm changing the page and jumping to an anchor. Is there a solution for this, or is it a bug with Unpoly?
PS. Thank you for this framework, it is really great.
The text was updated successfully, but these errors were encountered: