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

后端 未结 7 1317
予麋鹿
予麋鹿 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条回答
  •  萌比男神i
    2020-12-05 18:18

    You can use next code if you want to do any other action:

    $('[id^="item"]').each(function(){
      if(this.id.slice(-1) == 2){
        //Do something
        $(this).html('D');
      }
    
    });
    

提交回复
热议问题