Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

More compact/readable way of doing $($(this).children()[1]).html()) with jQuery

Tags:

jquery

I often find myself doing things like this when manipulating tables:-

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

For when I want the cell in the 3rd column as a jQuery wrapped set. Selecting the node using [n] and then passing to $() to get a jQuery wrapped set.

Is there a neater more readable way to do this?

like image 359
rgvcorley Avatar asked May 24 '12 23:05

rgvcorley


1 Answers

Use the .eq() method

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

you could alternatively use the :eq selector

$('table tr > :eq(2)').html();
like image 101
Gabriele Petrioli Avatar answered Sep 21 '22 12:09

Gabriele Petrioli