cucuru cucuru - 1 month ago 6
HTML Question

access to a table tr with index

I want to get a row content in my table:

<div class="myTable">
<table id="dataTable">
<tbody>
<tr>
<td>First</td>
</tr>
<tr>
<td>second</td>
</tr>
</tbody>
</table>
</div>


To get the td I use:

$('#dataTable').find('tbody').find('tr:nth-child(1)');


wich works and get the tr data, but, when do it with variable:

var j= 1;
$('#dataTable').find('tbody').find('tr:nth-child(j)');


it fails.

What is the problem?

Answer
var j= 1;
 $('#dataTable').find('tbody').find('tr:nth-child(' + j +')');
Comments