Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery find to get the first element

People also ask

How do you select the first element with the selector statement?

The :first selector selects the first element. Note: This selector can only select one single element. Use the :first-child selector to select more than one element (one for each parent). This is mostly used together with another selector to select the first element in a group (like in the example above).

How do I get the first option selected in jQuery?

Select the <select> element using JQuery selector. This selector is more specific and selecting the first element using option:nth-child(1). This will get access to the first element (Index starts with 1).

Is first child jQuery?

It is a jQuery Selector used to select every element that is the first child of its parent. Return Value: It selects and returns the first child element of its parent.

How do I get the first row of a table in jQuery?

var $row = $(this). closest('table'). children('tbody'). children('tr:first').


You can use either

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

or

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

Use :first selector like below :

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

using jquery simply use:

    $( "form" ).first().toggle('slow');

I use

$([selector]).slice(0, 1)

because it's the most explicit way to select a slice of a query and because it can be easily modified to match not the first element but the next, etc.


The simplest way to get the first result of find is with good old [index] operator:

$('.comment').find('form')[0];

Works like a charm!