Skip to content

Not working with identifiers starting with a digit. #532

@JulianCataldo

Description

@JulianCataldo

Hello there.

Got this error when trying to scroll to an anchor with an ID starting with a digit :

vue-scrollto.js?f13c:180 Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#3-scripts' is not a valid selector.

Notes : IDs are generated with rehype slug, using github-slugger

ID with a digit first are valid spec int HTML, but not a valid CSS Selector. Could be possible to failsafe that without changing slug generation policy though.

Some insights :
https://stackoverflow.com/questions/20306204/using-queryselector-with-ids-that-are-numbers

https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape

document.querySelector("[id='1']")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions