A more compact / readable way to execute $ ($ (this) .children () [1]). Html ()) with jQuery

I often find that I do such things when manipulating tables: -

$($('table tr').children()[2]).html();

For when I want the cell in the third column to be merged in jQuery. Selecting node with [n], and then moving on $()to get a complete jQuery set.

Is there a tidier, more readable way to do this?

+5
source share
1 answer

Use method .eq()

$('table tr').children().eq(2).html();

you can also use the selector :eq

$('table tr > :eq(2)').html();
+7
source

All Articles