开发者

jQuery Greater than non-selector?

开发者 https://www.devze.com 2023-04-06 15:11 出处:网络
I am trying to figure out how to use greater than in jQuery without a selector ? $(\'.myClass\').gt(2).css(\'width\',\'100px\');

I am trying to figure out how to use greater than in jQuery without a selector ?

$('.myClass').gt(2).css('width','100px');

My problem is that I am using this in a for s开发者_开发知识库tatement and I can't use the selector :gt().

So how would I do this ?


Use the slice method:

myItems.slice(2).css('width', '100px');


I think you're looking for the slice method, which behaves as you would expect:

$('.myClass').slice(2).css('width','100px'); // get the third elements and all subsequent elements and change their styles

This has the added advantage of being able to specify a range, rather than just a start point:

$('.myClass').slice(2, 5).css('width', '100px'); // select elements 2 through to 5
0

精彩评论

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

关注公众号