I have a table a row and multiple tds in that row, like that:
<tr class="first odd">
<td class="a-center">
<td>...</td>
<td>...</td> --> I want this
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
I am able to get the parent tr of all the tds, but is there a way to get the 3rd td inside the tr only?
The code to get the tr is:
jQuery('#shopping-cart-table > tbody > tr').each(function(index, value) {
...
});
Thanks
jQuery :nth-of-type() SelectorThe :nth-of-type(n) selector selects all elements that are the nth child, of a particular type, of their parent. Tip: Use the :nth-child() selector to select all elements that are the nth child, regardless of type, of their parent.
How can get TD table row value in jQuery? $('#mytable tr'). each(function() { var customerId = $(this). find(“td:first”).
The <td> tag defines a standard data cell in an HTML table. An HTML table has two kinds of cells: Header cells - contains header information (created with the <th> element) Data cells - contains data (created with the <td> element)
jQuery :nth-child() SelectorThe :nth-child(n) selector selects all elements that are the nth child, regardless of type, of their parent. Tip: Use the :nth-of-type() selector to select all elements that are the nth child, of a particular type, of their parent.
You can use :eq
selector:
jQuery('#shopping-cart-table > tbody > tr').each(function(index, value) {
$('td:eq(2)', this)
});
Or:
jQuery('#shopping-cart-table tbody').find('td:eq(2)');
Use the :eq function in jQuery: http://api.jquery.com/eq/
$('#shopping-cart-table td').eq(2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With