Select elements with id attribute that starts/ends with a particular value

后端 未结 7 1309
予麋鹿
予麋鹿 2020-12-05 17:55

Can jQuery or JavaScript be used with a regex to select multiple elements with similar id?

I have the following paragraphs:

7条回答
  •  一生所求
    2020-12-05 18:17

    The best way to go is to use the following jQuery selectors

    ^= is starts with
    $= is ends with
    
    =  is exactly equal
    != is not equal
    *= is contains
    

    So in your case:

    var $items = $('[id^="item"][id$="2"]');
    

提交回复
热议问题