jquery 3.x : Syntax error, unrecognized expression: a[href=#selectorId]
OlivierDelalande opened this issue · comments
Hello,
While updating jquery to a newer version (from 2.1.1 to 3.6.0), I have experienced an issue that I cannot troubleshoot.
The issue comes from the scrollSpy function of jquery which is awaiting a valid jquery selector.
But as you can see the error message in the title Syntax error, unrecognized expression: a[href=#selectorId]
.
I figured out that the selector ID is automatically minimized and stripped from the HTML content of the <h*>
element.
Maybe something related to the formatting during the selector ID injection, what do you think about that ?
Have you already experienced something similar ?
Thank you for your help
Olivier
Hey @OlivierDelalande, thanks for reaching out.
Is this issue for javascript-kit
? This package has been deprecated and replaced by prismicio/prismic-javascript
which is actively maintained.
That being said, I think your jQuery issue has to do with your selector syntax. #
is a special character when using attribute selectors. You probably need to escape the #
character using \\
.
Example:
a[href=\\#selectorId]
See introduction here: https://api.jquery.com/category/selectors/
Thanks a lot for your quick answer 🙏