admin管理员组文章数量:1201413
What is the difference between $('#div1 a')[0]
and $('#div1 a').eq(0)
for the following markup
<div id="div1">
<a href="#">click</a>
</div>.
Please Help.
What is the difference between $('#div1 a')[0]
and $('#div1 a').eq(0)
for the following markup
<div id="div1">
<a href="#">click</a>
</div>.
Please Help.
Share Improve this question edited Mar 14, 2013 at 21:27 Soenhay 4,0486 gold badges38 silver badges61 bronze badges asked Feb 15, 2011 at 7:56 Niraj ChoubeyNiraj Choubey 4,04018 gold badges60 silver badges94 bronze badges 4- In your markup, all three will return the same. (no difference) – bcm Commented Feb 15, 2011 at 8:07
- Using the square brackets is a shorthand for using .get api.jquery.com/get – Martin Jespersen Commented Feb 15, 2011 at 8:16
- @meo I get you... looking at your hide example... thanks for correcting – bcm Commented Feb 15, 2011 at 8:21
- This question took a while to find until I changed my search string from "jquery, .eq[0] vs [0]" to "jquery, difference between .eq[0] and [0]" – Soenhay Commented Mar 14, 2013 at 21:24
1 Answer
Reset to default 28$('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()
本文标签: javascriptDifference between (39selector39)0(39selector39)eq(index) in jqueryStack Overflow
版权声明:本文标题:javascript - Difference between $('selector')[0] ,$('selector').eq(index) in jquery. - Stack Ove 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738597491a2101869.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论