jQuery Greater than non-selector?
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
精彩评论