Alex Rivera | Logout

How to select and change value of table cell with jQuery?

Asked 2011-01-19T15:58:30.390
33

How do I change the content of the cell containing the 'c' letter in the HTML sample using jQuery?

<table id="table_header">
<tr>
   <td>a</td>
   <td>b</td>
   <td>c</td>
</tr>
</table>

Thanks.

Edit
Report

1 Answer

17

Using eq() you can target the third cell in the table:

$('#table_header td').eq(2).html('new content');

If you wanted to target every third cell in each row, use the nth-child-selector:

$('#table_header td:nth-child(3)').html('new content');
answered 2011-01-19T16:06:31.523

Your Answer