How can I use a variable in a jQuery attribute selector?

Prior to jQuery 1.7

The following will work:

$('.tabContent img[value="+selectboxvalue+"]').css({border: '1px solid #c10000'});

jQuery 1.7 and later

In 1.7 jQuery changed the syntax to require the attributes to have quotation around the value:

$('.tabContent img[value="'+selectboxvalue+'"]').css({border: '1px solid #c10000'});

Leave a Comment