Safari - Error: Syntax error, unrecognized expression: input[data-card-type="payment-one

caroline picture caroline · Aug 21, 2015 · Viewed 10.3k times · Source

on mac Safari (and older versions of FF v.38 and older) we are receiving the following error:

Error: Syntax error, unrecognized expression: input[data-card-type="payment-one"

jQuery Version: https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js

$(this).change(function() {
  if($(this).val() != '' ) {
    $('input[data-card-type="'+paymentGroup+'"').val('').prop('disabled',true);

In Safari's Console, in red it reads: Error: Syntax error, unrecognized expression: input[data-card-type="payment-one and beneath the error it reads: (anonymous function)

Does any of this look like it conflicts with jQuery 2.1.4, or maybe there is something else incorrect?

Answer

ericjbasti picture ericjbasti · Aug 21, 2015

This looks like it's a Safari issue, but really it never should have worked. You need to close the [data-card-type=paymentGroup statement, without that ending ] Safari will throw a fit. I know this from experience. Chrome (my main dev browser) will let this fly without a single peep, but Safari breaks (and rightfully so, its not valid).

Replace your code with this:

$(this).change(function() {
   if($(this).val() != '' ) {
     $('input[data-card-type="'+paymentGroup+'"]').val('').prop('disabled',true);