2

I have a table with 14 table row and 3 column of data

i like to select the table, each row only the value of the #3 column

how do i count, i know the fisrt selector, the child... but how to not net

$('#tableofdata tr td).getmethethird

1

4 Answers 4

6
$("#tableofdata tr td:nth-child(3)") 

or simply:

$("#tableofdata tr td:last-child") 

To grab the 3rd child from this, there are a number of ways:

$(this).find(":nth-child(3)"); 

or:

$(":nth-child(3)", this); 

or simply:

$(this)[2]; // arrays are 0 indexed 
Sign up to request clarification or add additional context in comments.

3 Comments

i think the child(3) method is the best for me... just a question the first td is #1 or #0 ?
and how to get the child(3) from $(this)
$(this).find(":nth-child(3)") or $(":nth-child(3)", this)
1

Not certain if this will be the fastest but...

$('#tableofdata tr td + td + td') 

1 Comment

if Child(3) dont exist it will be my solution... cannot see how to get the 245 td of 367.... it will be ugly !
0

what about that solution :

$('#mytable tr').each(function() { var customerId = $(this).find("td").eq(2).html(); } 

Comments

0

The problem with this solution:

$('#mytable tr').each(function() { var customerId = $(this).find("td").eq(2).html(); }); 

Is that if your table looks like this:

<table id='mytable'> <tr> <td>col1</td> <td>col2</td> <td>15</td> </tr> <tr> <td>col1</td> <td>col2</td> <td>16</td> </tr> </table> 

It would only get the ID of the first row because of the way it is constructed. So if you wanted to get all the IDs, you would do this:

var customers = new Array(); $('#mytable tr td:nth-child(2)').each(function() { customers.push($(this).html()); }); 

If you wanted the specific customer id of the Nth row, you would do this:

var customerId = $('#mytable tr').eq(N).find('td').eq(2).html(); 

Where N would be the 0-based index of the row you want.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.