jQuery : eq() vs get()

前端 未结 8 1218
挽巷
挽巷 2020-11-28 03:50

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()

8条回答
  •  死守一世寂寞
    2020-11-28 04:34

    eq(i) retrieves the ith member in the receiver's set as a jQuery object, while get(i) returns the member at the ith position as a DOM element.

    The reason why this doesn't work:

    $("h2").get(0).fadeIn("slow");
    

    Is because the h2 DOM element doesn't have a method called fadeIn.

    You should use eq(0) here instead.

提交回复
热议问题