开发者

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

开发者 https://www.devze.com 2023-02-03 12:51 出处:网络
What is the difference between var row1 = $(\'tr\').get(0);开发者_StackOverflow社区 and var row2 = $(\'tr\').eq(0);

What is the difference between

var row1 = $('tr').get(0);开发者_StackOverflow社区

and

var row2 = $('tr').eq(0);


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消