scroll-to-element icon indicating copy to clipboard operation
scroll-to-element copied to clipboard

Scroll to an element with ID with a leading number crashes

Open dhakan-k opened this issue 4 years ago • 3 comments

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?

dhakan-k avatar Feb 19 '21 08:02 dhakan-k

I have the same problem!

buondevid avatar Oct 16 '21 22:10 buondevid

Same problem.

And these are valid HTML5 ids.

cesarvarela avatar Nov 17 '21 20:11 cesarvarela

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

erikyo avatar Oct 08 '22 11:10 erikyo