Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between using .first() and .eq(0)? [duplicate]

Tags:

jquery

What are the difference between using these 2 methods for retrieving the first element in a collection?

like image 925
Andrei Oniga Avatar asked Dec 20 '22 07:12

Andrei Oniga


1 Answers

Taken from the live source code of jQuery 1.7.1:

,first:function(){return this.eq(0)},last:function(){return this.eq(-1)}

So as you suspected .first() is just a wrapper calling .eq().

Conclusion: no difference whatsoever. :)

like image 155
Shadow Wizard Hates Omicron Avatar answered Dec 22 '22 19:12

Shadow Wizard Hates Omicron