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
source share
6 answers

You can use the selector :eq:

jQuery('#shopping-cart-table > tbody > tr').each(function(index, value) {
    $('td:eq(2)', this)
});

Or:

jQuery('#shopping-cart-table tbody').find('td:eq(2)');
+10
source

Use function: eq in jQuery: http://api.jquery.com/eq/

$('#shopping-cart-table td').eq(2);
+2
source

$("#shopping-cart-table >  tbody > tr td").eq(2);
+1

:

$(".first td:nth-child(3)").append("<span>-3rd");
+1

. , . :

<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

:

$("#tableId tr td:nth-child(3)").html();
0
source

All Articles