Skip to content
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

Scroll to an element with ID with a leading number crashes #14

Open
dhakan-k opened this issue Feb 19, 2021 · 3 comments · May be fixed by #15
Open

Scroll to an element with ID with a leading number crashes #14

dhakan-k opened this issue Feb 19, 2021 · 3 comments · May be fixed by #15

Comments

@dhakan-k
Copy link

dhakan-k commented Feb 19, 2021

Hi! When scroll-to is used on an element with ID containing a leading number, it crashes on:

Uncaught DOMException: Document.querySelector: '1-Sign-Up-to-create-the-User' is not a valid selector

One solution I could find was to utilize the CSS.escape function to handle these cases. Something like:

document.querySelector(`#${CSS.escape("1-Sign-Up-to-create-the-User")}`)

The crashing line is https://github.com/willhoag/scroll-to-element/blob/master/index.js#L30.

Thoughts?

@buondevid
Copy link

I have the same problem!

@cesarvarela
Copy link

Same problem.

And these are valid HTML5 ids.

gretchenfitze added a commit to gretchenfitze/scroll-to-element that referenced this issue Jul 25, 2022
@erikyo
Copy link

erikyo commented Oct 8, 2022

Same problem.

And these are valid HTML5 ids.

yes it's valid but usually doesn't work. Anyhow you can "escape" the id's with leading numbers in this way https://mothereff.in/css-escapes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants