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>
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.
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.
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.
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.
There's essentially no difference between them, except in performance. jQuery has many methods that are equivalent to selectors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With