Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
43
rated 0 times [  44] [ 1]  / answers: 1 / hits: 37042  / 13 Years ago, wed, may 25, 2011, 12:00:00

I have a selectbox with several options - each of these option values correspond to a value attribute on some images below. The functionality I want is when selectbox value is changed the img with the corresponding value is highlighted with a red border. Here is the code:



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

$('#Box_style').change(assignValue);


Looking around at the jquery documentation (http://api.jquery.com/attribute-equals-selector), apparently this should work...



Any help would be appreciated, Thank you!


More From » jquery

 Answers
3

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'});

[#92048] Tuesday, May 24, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaleyv

Total Points: 259
Total Questions: 99
Total Answers: 107

Location: Saint Helena
Member since Tue, Nov 3, 2020
4 Years ago
;