scroll-to-element
scroll-to-element copied to clipboard
Scroll to an element with ID with a leading number crashes
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?
I have the same problem!
Same problem.
And these are valid HTML5 ids.
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