开发者

Difference between $('selector')[0] ,$('selector').eq(index) in jquery.

开发者 https://www.devze.com 2023-02-11 15:25 出处:网络
What is the difference开发者_Python百科 between $(\'#div1 a\')[0] and $(\'#div1 a\').eq(0) for the following markup

What is the difference开发者_Python百科 between $('#div1 a')[0] and $('#div1 a').eq(0) for the following markup

<div id="div1">
<a href="#">click</a>
</div>.

Please Help.


$('div1 a')[0]

returns a direct reference to a DOM element

$('div1 a').eq(0)

returns a JQuery object

http://jsfiddle.net/meo/DP8as/

This will not work:

$('div a')[0].hide()

this will;

$('div a').eq(0).hide()
0

精彩评论

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