Uncaught Error: Syntax error, unrecognized expression: [href=#]

I’m running a WordPress website for a client and getting this in the console.

Uncaught Error: Syntax error, unrecognized expression: [href=#]

Read More

I know about this error with the latest WordPress update:

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

However my error seems to be something else. Can anyone tell me what I should be looking at to fix this? Thanks.

Related posts

Leave a Reply

2 comments

  1. You need to wrap the # in quotes in the selector so that it is not interpreted as an id selector:

    $('[href="#"]');
    
    $('a[href*="#"]:not([href="#"]);
    
  2. From the spec

    Attribute values must be CSS identifiers or strings.

    and

    In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_);

    # is not a valid identifier, so you have to represent it as a string, so you have to surround it with quotes.

    Such:

    a[href*="#"]:not([href="#"])