开发者

jQuery - is there shortern notation for the following statement?

开发者 https://www.devze.com 2023-04-11 13:36 出处:网络
I want to select elements that have similar incrementally-based names. Is there shorter notation to do the same thing?

I want to select elements that have similar incrementally-based names. Is there shorter notation to do the same thing?

$('#galnav1,#galnav2,#galnav3,#galnav4,#galnav5,#galnav6,#galnav7,#galnav8,#g开发者_如何转开发alnav9,').each(function(){
    ... 
});


How about this one:

$('[id^=galnav]');

$('[id^=galnav]').filter(function() {
    return /v\d$/.test($(this).attr('id'));
});


You can use this jquery selector

$('[id^="galnav"]').each(function(){
    ... 
});
0

精彩评论

暂无评论...
验证码 换一张
取 消