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

后端 未结 7 1343
予麋鹿
予麋鹿 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:10

    You can use "start with" and "ends with" selectors provided by jQuery, like below.

    $("[id^='item'][id$='2']").html("D");
    

    Official documentation:

    • Start with selector
    • Ends with selector

提交回复
热议问题