I'm new to jQuery, and I'm wondering what the difference is between jQuery's get()
and eq()
functions. I may misunderstand what the get()
function does, but I thought it odd that I couldn't call a function on the returned on the returned element in the same line.
//Doesn't work
I.e. $("h2").get(0).fadeIn("slow");
//Works
$("h2").eq(0).fadeIn("slow");
jQuery eq() method selects a HTML element with a specific index number.
Here is an example of that
Source: http://www.snoopcode.com/JQuery/jquery-eq-selector
get(0)
(docs) returns the first DOM element in the set.eq(0)
(docs) returns the first DOM element in the set, wrapped in a jQuery object.That's why
.fadeIn("slow");
doesn't work when you do.get(0)
. A DOM element doesn't have afadeIn()
method, but a jQuery object does.