Selecting element which starts with “abc” and ends with “xyz”

前端 未结 3 1021
误落风尘
误落风尘 2021-01-23 00:21

I have elements in my page with ids like \"abc_1_2_3_xyz\" .How do I select element in Jquery which starts with \"abc\" and ends with \"xyz\"?

$(\'div[id^=\"abc         


        
3条回答
  •  暖寄归人
    2021-01-23 01:11

    Use filter:

    $('div')
        .filter(function() {
            return this.id.match(/^abc+xyz$/);
        })
        .html("Matched!")
    ;
    

提交回复
热议问题