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

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


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.

Tags:

Jquery