选择以"abc"开头的元素以“xyz"”结尾

Selecting element which starts with "abc" and ends with "xyz"

本文关键字:quot xyz 结尾 开头 abc 选择 元素      更新时间:2023-09-26

我有元素在我的页面与id像"abc_1_2_3_xyz" .我如何选择元素在Jquery以"abc"开始,以"xyz"结束?

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

可以使用2个属性选择器

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

尝试如下:

$('div[id^="abc"][id$="xyz"]');
http://api.jquery.com/multiple-attribute-selector/

使用过滤器:

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