Is there a simple way to get li:gt(-1) in jquery?
Is there a simple way to get li:gt(-1)
in jQuery? Or greater than or equal to zero using jQuery's :gt
filter?
When the I use the following code, it is not taking li:gt(-1)
:
$('#Input li:gt(-1)').each(function()
开发者_运维百科
Change your code to start at 0 instead of -1, and do a "greater-than-or-equal-to" selector:
$('.someClass:eq('+i+'), .someClass:gt('+i+')')
Or, with a little less duplication:
$('.someClass').filter(':eq('+i+'), :gt('+i+')')
What about .slice
? Passing one index means anything from that index and up, so add 1
to get gt
rather than gte
.
$('#Input li').slice(1 - l)
If you want to get all elements at index "greater than or equal to zero" then you just want all the elements, and you don't need the :gt
pseudo-selector:
$('#Input li').each(function() {
//Do whatever
});
Update (based on comments)
I'm still not exactly sure what you're aiming for, but if you want to know the index of the element referred to by the current iteration, you can use the first argument of each
:
$('#Input li').each(function(index, elem) {
//index is the index of the current element
});
If I understand the question, I think you just need:
$('#Input li').each(function()
It will return a jQuery object that is indexed from 0.
Therefore every match will be 0 or greater.
精彩评论