19

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!

2
  • I think your problem is simply that you mixed up ' and ". Commented Jul 9, 2017 at 7:05
  • @kinsey This is a failure to understand basic string operations, not the functionality of jQuery. It would be a good idea for you to try to understand strings and concatenation. The actually What and Why of the problem, not the How. If you are programming in a text editor an IDE with syntax highlighting (and understanding why things highlight the way they do) would help a bunch Commented Aug 2, 2018 at 14:54

3 Answers 3

45

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'});
Sign up to request clarification or add additional context in comments.

Comments

7

Quotes are messed up:

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

Comments

1

To the above, it no longer works as mentioned above (, though it might also be only my code). The single quotation messes up the code. The following code works

As of jQuery 3.2.1 and later

$("#clickmap a[gruppe="+gruppeId+"]").children("path").addClass('lastClicked');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.