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

When using an attribute-based selection, we frequently get the jQuery error “Syntax error, unknown expression for href” because we failed to wrap unusual characters in quotation marks. It must be encapsulated in double quotation marks.

if ($(this).is('[href$=#abc]')) {

});

The code contained in the if statement above will not run due to an error that looks like “Uncaught Error: Syntax error, unrecognized expression.” Double quotation marks (“”) must be placed between each href hash tag. Let’s utilize the proper format, as shown below, to resolve this issue.

if ($(this).is('[href$="#abc"]')) {

});

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart