Niraj Choubey Niraj Choubey - 1 year ago 106
Javascript Question

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

What is the difference between

$('#div1 a')[0]
$('#div1 a').eq(0)
for the following markup

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

Please Help.

meo meo
Answer Source
$('div1 a')[0]

returns a direct reference to a DOM element

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

returns a JQuery object

This will not work:

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

this will;

$('div a').eq(0).hide()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download