Search code examples
javascriptjquery

"Syntax error, unrecognized expression" error whilst using jQuery. What am I doing wrong?


I have Googled this exception, and it seems to mostly boil down to people using the old option[@select] style attribute selector.

My problem, however, is a little different. When I get the error, there is no line number being attributed to it.

I think it has something to do with the hashes I am using for my page.

I have tried a lot of console.log(), etc, but haven't been able to figure it out. This is happening in Firefox and Safari.

What am I doing wrong?


Solution

  • The problem is with this line:

    $(window.location.hash).find('.info').css({ display: 'block' });
    

    The $(window.location.hash) means you would be looking for an element in the page with the hash as a selector.

    You probably meant to do:

    $(window.location.hash.replace('!/', '')).find('.info').css({ display: 'block' });