Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select the 3rd <td> using jQuery?

Tags:

jquery

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

like image 424
user1856596 Avatar asked Feb 19 '13 12:02

user1856596


People also ask

How to select nth element in jQuery?

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 of TR in jQuery?

How can get TD table row value in jQuery? $('#mytable tr'). each(function() { var customerId = $(this). find(“td:first”).

What is TD in jQuery?

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)

How to use nth child in jQuery?

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.


2 Answers

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)');
like image 66
undefined Avatar answered Nov 15 '22 23:11

undefined


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

$('#shopping-cart-table td').eq(2);
like image 44
Chris Dixon Avatar answered Nov 15 '22 22:11

Chris Dixon