Search code examples
jqueryjquery-tools

jquery tools error: Uncaught Error: Syntax error, unrecognized expression: [href=/]


I just loaded jQuery Tools onto my site. But the Google Chrome console shows an error:

Uncaught Error: Syntax error, unrecognized expression: [href=/] (http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js)

The jQuery version I am using is 1.7.1

How to deal with this problem?


Solution

  • I'm assuming you have a selector that is meant to match elements with an href attribute value of /. You will need to put the / character in quotes:

    var elems = $("[href='/']");
    

    Alternatively, you can escape the character:

    var elems = $("[href=\\/]");
    

    From the jQuery docs:

    If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^{|}~` ) as a literal part of a name, you must escape the character with two backslashes: \\.

    Here's a working example. Remove the quotes to generate the same error you mention in your question.