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

后端 未结 1 1248
Happy的楠姐
Happy的楠姐 2021-02-08 10:15

What is the difference between $(\'#div1 a\')[0] and $(\'#div1 a\').eq(0) for the following markup


      
1条回答
  •  孤街浪徒
    2021-02-08 10:53

    $('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 讨论(0)
提交回复
热议问题