acidzombie24 acidzombie24 - 4 months ago 12
Javascript Question

jquery find to get the first element

I am writing

$(this).closest('.comment').find('form').toggle('slow');
and the problem is each of the forms in the child is being toggled. I would like only the first form to be toggled. the html is something like the below and this is the a link

<div comment>
<a href>
<form>
</form>
<a href>
<div comment>
<form>
</form>
</div>
</div>

Answer

You can use either

$(this).closest('.comment').find('form').eq(0).toggle('slow');

or

$(this).closest('.comment').find('form:first').toggle('slow');
Comments