Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between get() and eq() in jquery?

What is the difference between

var row1 = $('tr').get(0);

and

var row2 = $('tr').eq(0);
like image 965
Niraj Choubey Avatar asked Jan 11 '11 20:01

Niraj Choubey


People also ask

What is EQ () 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).


1 Answers

get(0) returns the first DOM element matched by the selector.

eq(0) returns a jQuery object containing the first DOM element matched by the selector.

In other words, $("selector").get(0) is equivalent to $("selector").eq(0).get(0).

like image 96
Frédéric Hamidi Avatar answered Oct 02 '22 13:10

Frédéric Hamidi