2

I have a page which references jQuery 3.3.1, jQuery-Migrate 1.4.1 and Bootstrap 3.3.7. When I click anywhere on the page, I get the following error in the console:

jquery-3.3.1.js?v=2018.8.0.1-develop:1541 Uncaught Error: Syntax error, unrecognized expression: #
    at Function.Sizzle.error (jquery-3.3.1.js?v=2018.8.0.1-develop:1541)
    at Sizzle.tokenize (jquery-3.3.1.js?v=2018.8.0.1-develop:2193)
    at Sizzle.select (jquery-3.3.1.js?v=2018.8.0.1-develop:2620)
    at Function.Sizzle (jquery-3.3.1.js?v=2018.8.0.1-develop:845)
    at Function.a.find (jquery-migrate-1.4.1.min.js?v=2018.8.0.1-develop:2)
    at jQuery.fn.init.find (jquery-3.3.1.js?v=2018.8.0.1-develop:2873)
    at jQuery.fn.init.a.fn.find (jquery-migrate-1.4.1.min.js?v=2018.8.0.1-develop:2)
    at a.fn.init.jQuery.fn.init (jquery-3.3.1.js?v=2018.8.0.1-develop:2983)
    at new a.fn.init (jquery-migrate-1.4.1.min.js?v=2018.8.0.1-develop:2)
    at jQuery (jquery-3.3.1.js?v=2018.8.0.1-develop:139)

From the error unrecognized expression: #, it's clear to me that there is code like below, where the variable is either blank/null/undefined:

$('#' + someBlankVariable).method();

I searched for '#' + and placed breakpoints on all found instances and none of them are getting hit with a blank variable.

So, given that the entire error stack is in jQuery and jQuery-migrate, how can I determine what is actually causing the error?

22
  • Usually caused by incompatible versions of JQ migrate? Commented Jan 26, 2019 at 0:29
  • This looks like a missin quote (or double quote) in a jQuery selector somewhere. For that kind of stuff, I use Agent Ransack to keyword search through code files. Commented Jan 26, 2019 at 0:32
  • 1
    @LouysPatriceBessette These are all "old" files. I upgraded from jQuery 1.7.2 to 3.3.1. In 1.7.2 $(#) would basically return nothing. In the current version, it throws the error. Commented Jan 26, 2019 at 1:08
  • 1
    @LouysPatriceBessette I got to the bottom of it. Found it when QA reported that the Share link wasn't working (with the same error). The issue was data-target="#" attribute in an <a href="" element. Once I removed it all errors went away. I am still confused why an attribute on a link attribute caused an error when simply clicking on a page. Perhaps the event was bubbling up. Thanks for the help. Commented Jan 30, 2019 at 18:24
  • 1
    Man... Keep breathing. You are on a Q/A website. While having a QA peek question versus jQuery version (and migration sh%t). --- If you found an answer yourself, you can answer yourself on SO (and earn some rep points). Be as descriptive as you can ;) --- I'm sure you know that. Commented Jan 30, 2019 at 22:47

1 Answer 1

0

It generating cause of the following attribute:

href="#"

Replacing it with the attribute

href="javascript:void(0)"

Not the answer you're looking for? Browse other questions tagged or ask your own question.