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

前端 未结 3 1015
误落风尘
误落风尘 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:03

    Try the following:

    $('div[id^="abc"][id$="xyz"]');
    

    http://api.jquery.com/multiple-attribute-selector/

    0 讨论(0)
  • 2021-01-23 01:11

    Use filter:

    $('div')
        .filter(function() {
            return this.id.match(/^abc+xyz$/);
        })
        .html("Matched!")
    ;
    
    0 讨论(0)
  • 2021-01-23 01:24

    You can use 2 attribute selectors.

    $('div[id^="abc"][id$="xyz"]');
    
    0 讨论(0)
提交回复
热议问题