Select third <td> using jQuery?
I have a row table and several tds in this row, for example:
<tr class="first odd">
<td class="a-center">
<td>...</td>
<td>...</td> --> I want this
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
I can get the parent tr of all tds, but is there a way to get the third td inside tr only?
Code to get tr:
jQuery('#shopping-cart-table > tbody > tr').each(function(index, value) {
...
});
thank
+5
6 answers
Use function: eq in jQuery: http://api.jquery.com/eq/
$('#shopping-cart-table td').eq(2);
+2
. , . :
<tr class="first odd">
<td class="a-center">
<td>...</td>
<td>...</td> --> I want this
<td>...</td>
<td>...</td>
<td><button id='test'><button></td>
</tr>
javascript click, : -
$(document).ready(function () {
$('#test').click(function(){
var thirdData = $(this).closest('tr').children('td:eq(2)').text();
alert(thirdData);
});
});
.
0