NorCalKnockOut
NorCalKnockOut

Reputation: 878

Get eq( ) and nth-child of table

I have the following table:

<table id="some-table">
<thead>
  <tr>
    <th>Name</th>
    <th>Type</th>
    <th>UI Status</th>
    <th>Engine Status</th>
 </tr>
</thead>
<tbody>
<tr>
    <th>A</th>
    <th>1</th>
    <th></th>
    <th></th>
</tr>
<tr>
    <th>B</th>
    <th>2</th>
    <th></th>
    <th></th>
 </tr>
</tbody>
</table>

I want to insert the UI Status into the table at the index.

$(#'some-table tbody tr').eq(0) will get me the row that I want but how would I get the 3rd th in that tr so I can update the UI Status.

Any help is appreciated.

Thanks.

Upvotes: 1

Views: 619

Answers (1)

Guffa
Guffa

Reputation: 700382

You can chain calls to find children in the element:

$(#'some-table tbody tr').eq(0).find('th').eq(2)

You can also use the :eq pseudo class in the selector:

$(#'some-table tbody tr:eq(0) th:eq(2)')

Upvotes: 3

Related Questions