Reputation: 1915
i have a HTML table that looks somewhat like this
<tr rel="price">
<th>Price</th>
<td class="">-</td>
<td class="">-</td>
<td class="">-</td>
<td class="">-</td>
</tr>
how would i insert data the the 4th td? I could give the 4th td an ID and insert like this
$('#id').html('bla bla');
but my table has 60 rows and 4 columns. Personally think it would be abit messy if i was going to add ID's to all td's. Any suggestions? Obviously something that works fast on a big table would be ideal. Thanks
Upvotes: 0
Views: 172
Reputation: 5326
$("tr[rel=price] td:nth-child(3)").html('bla bla');
3 is because counting starts at 0, so that is the 4th element.
Upvotes: 1
Reputation: 18873
<tr rel="price" id="tr1">
<th>Price</th>
<td class="">-</td>
<td class="">-</td>
<td class="">-</td>
<td class="">-</td>
</tr>
$('table tbody #tr1').closest("td").eq(3).html('bla bla');
Upvotes: 0