jQuery attribute selector variable

后端 未结 3 1981
终归单人心
终归单人心 2020-11-27 19:50

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 va

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 20:27

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

提交回复
热议问题