As I upgrade older sites to use jQuery 3.3.1 I commonly encounter the following error:
Uncaught Error: Syntax error, unrecognized expression: ...
This error occurs when you are trying to select something with an invalid selector. jQuery 2.x and 3.x handle Sizzle related errors differently than 1.x, and will throw an Error in circumstances where jQuery 1.x wouldn’t, so it’s common to see this come up during an upgrade from 1.x.
To find the source of the issue I’d recommend the following steps.
*.js
file rather than a plugin.Review the codeline for any usage of a jQuery selector, and double check that it’s properly used. I usually see it come up when a dynamic selector is being used. For example, something like this:
$( '#' + someVariable )
If someVariable
is empty or false, then this will throw an error because $('#')
is an invalid selector expression.
Hopefully this help you track down the source of your unrecognized expression errors with jQuery.