[ACCEPTED]-Opposite of jQuery's :eq()-jquery-selectors
Alright, it's just
$("li:not(:eq(2))");
0
The other answers will work just fine, but 6 as an alternative you could implement you 5 own custom selector for neq
$.extend($.expr[":"], {
neq: function(elem, i, match) {
return i !== (match[3] - 0);
}
});
And then you could 4 do what you originally suggested.
$("li:neq(2)").size();
Although 3 another post suggested using .length
instead of 2 .size
, which will be better as its just a property 1 and not an extra function call.
$("li:neq(2)").length;
I would use filter for such case,
$('li').filter(function (i, item) {
return i != 2;
})
0
In addition to the custom selector, you 1 could also implement this as a jQuery plugin:
$.fn.neg = function (index) {
return this.pushStack( this.not(':eq(' + index + ')') );
}
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.