简体   繁体   中英

jQuery access each matched element from '.find' by an index

Using jQuery's .find() method to return a set of elements, I am trying to access items in the returned set by their order in that set.

For example, a table with two rows and in each row a select box and two text input fields, accessed with the following:

$('table#tbl').find('tr.row').each(function(i)
{

});

To get the first element I would have thought I could use

$('table#tbl').find('tr.row').each(function(i)
{
    alert( $(this).find(':input').get(1).val() );
});

And variations of the above, but apparently this doesn't work. Could anyone suggest the correct method to access item x of n elements returned?

Edit:

JSFiddle here: http://jsfiddle.net/Lenqt/42/

alert( $(this).find(':input:eq(0)').val() );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM