Jacksonkr
Jacksonkr

Reputation: 32247

query selector in jquery causing unrecognized expression

If I plug in the following into my console (Chrome):

$('input[name=shopping-cart.merchant-private-data]');

it results in:

Error: Syntax error, unrecognized expression: [name=shopping-cart.merchant-private-data]

Upvotes: 0

Views: 379

Answers (2)

Jacksonkr
Jacksonkr

Reputation: 32247

The real problem (and solution) actually dawned on me while posting.

The issue is the decimal place in the selector. You need to escape it with two backslashes like so:

$('input[name=shopping-cart\\.merchant-private-data]');

Upvotes: 4

MrOBrian
MrOBrian

Reputation: 2189

when creating selectors based on the value of an attribute, you should always surround the value in quotes:

$('input[name="shopping-cart.merchant-private-data"]');

Upvotes: 0

Related Questions