AngryHacker
AngryHacker

Reputation: 61646

How to find the source of the jQuery error?

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?

Upvotes: 2

Views: 649

Answers (1)

Nazim
Nazim

Reputation: 1

It generating cause of the following attribute:

href="#"

Replacing it with the attribute

href="javascript:void(0)"

Upvotes: 0

Related Questions