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

前端 未结 2 1186
生来不讨喜
生来不讨喜 2021-01-07 20:32

What is the difference between

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

and

var row2 = $(\'tr\').eq(0);
2条回答
  •  被撕碎了的回忆
    2021-01-07 21:06

    The .get() method returns a DOM element at the given index.

    The .eq() method returns a DOM element at the given index, wrapped in a jQuery object.

    Another difference is that if you don't pass an argument to .get(), it will return an Array of the DOM elements in the jQuery object.

提交回复
热议问题