Jquery: Syntax error, unrecognized expression: a[href*=#]:not([href=#])

Created on 29 Jan 2016  路  3Comments  路  Source: jquery/jquery

I have used $('a[href*=#]:not([href=#])') selectior somewhere in my code like this:

$('a[href*=#]:not([href=#])').click(function () {
    console.log("Hello World");
})

It has worked without any issue with jQuery v2.1.4 and jQuery migrate v1.2.1, but I get this error message when I try to use jQuery 2.2.0 and jQuery migrate 1.3.0:

Error: Syntax error, unrecognized expression: a[href*=#]:not([href=#])
jquery-2.2.0.js:1463:8

I'm using Firefox v44.0

Any Suggestion?!

Most helpful comment

your selector is not valid. # is a special char and needs to be escaped like 'a[href*=\\#]:not([href=\\#])'

see https://api.jquery.com/category/selectors/

All 3 comments

your selector is not valid. # is a special char and needs to be escaped like 'a[href*=\\#]:not([href=\\#])'

see https://api.jquery.com/category/selectors/

Yes, this is another duplicate of gh-2824.

This really helped me. After after a drupal site 8.3.7, the sub-menus no longer displayed. All i did was add the two backslash to the jQuery function.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guylando picture guylando  路  5Comments

Krinkle picture Krinkle  路  3Comments

enbo picture enbo  路  9Comments

jonathansampson picture jonathansampson  路  3Comments

mgol picture mgol  路  6Comments