Reputation: 465
Is there something wrong with the code below it just won't work, no errors?
var select_value = $("#cart-image").attr('alt');
if ($("select_value:contains('Aqua')")) { keyword = "aqua"; };
Upvotes: 0
Views: 978
Reputation: 93664
While all the other answers are correct, they forget to mention that you can use jQuery for this. There is the Attribute contains selector:
if ($("#cart-image[alt*=Aqua]").length) keyword = "aqua";
Upvotes: 4
Reputation: 6286
The double quotes are making jQuery interpret the "select_value" as a string, rather than the variable.
try
if (select_value.indexOf('Aqua') != -1) { keyword = "aqua"; };
Upvotes: 1
Reputation: 237827
You're using jQuery to do something that it is neither designed for nor capable of. Use Javascript's native functions to search strings for substrings:
if (select_value.indexOf('Aqua') > -1) {
keyword = 'aqua';
}
Upvotes: 1