Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of jQuery's :eq()

Does anyone know if there exist some kind of selector to select al the elements from a matched set but the one given by the indicated index. E.g.:

$("li").neq(2).size(); 

Supposing that there were 5 elements, the last statement would give you 4, and would contain all the <li> elements but the second one in the DOM.

like image 547
manutenfruits Avatar asked Aug 21 '12 14:08

manutenfruits


People also ask

What is the difference between EQ () and get () methods in jQuery?

eq() returns it as a jQuery object, meaning the DOM element is wrapped in the jQuery wrapper, which means that it accepts jQuery functions. . get() returns an array of raw DOM elements. You may manipulate each of them by accessing its attributes and invoking its functions as you would on a raw DOM element.

What is EQ method in jQuery?

jQuery eq() Method The eq() method returns an element with a specific index number of the selected elements. The index numbers start at 0, so the first element will have the index number 0 (not 1).

What is the following syntax is used to apply not equal filter on HTML elements using jQuery?

The not() is an inbuilt function in jQuery which is just opposite to the filter() method. This function will return all the element which is not matched with the selected element with the particular “id” or “class”.

Which of the following CSS selectors will select the second div in jQuery?

myclass:eq(1)" ) selects the second element in the document with the class myclass, rather than the first. In contrast, :nth-child(n) uses 1-based indexing to conform to the CSS specification. Prior to jQuery 1.8, the :eq(index) selector did not accept a negative value for index (though the . eq(index) method did).


2 Answers

Use not:

$('li').not(':eq(2)'); 
like image 105
Zbigniew Avatar answered Sep 21 '22 05:09

Zbigniew


Alright, it's just

$("li:not(:eq(2))"); 
like image 27
manutenfruits Avatar answered Sep 21 '22 05:09

manutenfruits