Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ":eq()" and .eq()

Tags:

jquery

I have recently started learning jQuery. Considering follwing html structure, I want to know, what is basic difference between selectors $('ul>li:eq(2)') and $('ul>li').eq(2).

<ul>
    <li>one</li>
    <li>two</li>
    <li>three</li>
    <li>four</li>
    <li>five</li>
</ul>
like image 232
Manish Avatar asked Dec 15 '13 07:12

Manish


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 are the differences between EQ Eqv and equal?

Two objects that are eq are both eqv and equal. Two objects that are eqv are equal, but not necessarily eq. Two objects that are equal are not necessarily eqv or eq. eq is sometimes called an identity comparison and equal is called an equality comparison.

What does EQ mean in scheme?

equal? for numbers reduces to = , 2.5 and 2.5 are numerically equal. eq? compares 'pointers'. The number 5, in your Scheme implementation, is implemented as an 'immediate' (likely), thus 5 and 5 are identical.


2 Answers

They do the same thing, but one is significantly slower: http://jsperf.com/eq-vs-eq

:eq() is not a CSS pseudo-selector, which makes the first selector a jQuery selector. Therefore, it has to be parsed by the Sizzle selector library, which is written in JavaScript.

The second one is a regular CSS selector and will be passed directly into document.querySelectorAll, which is implemented natively and will end up running much faster.

like image 111
Blender Avatar answered Nov 06 '22 10:11

Blender


There's essentially no difference between them, except in performance. jQuery has many methods that are equivalent to selectors.

like image 24
Barmar Avatar answered Nov 06 '22 11:11

Barmar