tags:

views:

435

answers:

6

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  A: 

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

$('#tableofdata tr td + td + td')
Eric Wendelin
if Child(3) dont exist it will be my solution... cannot see how to get the 245 td of 367.... it will be ugly !
marc-andre menard
nth-child(3) will work fine.
Eric Wendelin
+4  A: 
$("#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
cletus
i think the child(3) method is the best for me... just a question the first td is #1 or #0 ?
marc-andre menard
first child is 1. http://docs.jquery.com/Selectors/nthChild#index
cletus
and how to get the child(3) from $(this)
marc-andre menard
$(this).find(":nth-child(3)") or $(":nth-child(3)", this)
cletus
or $(this).children()[3] probably works too
cletus
A: 

how do we write it with $(this)

is $(this td:nth-child(3)) is valid or what will be the RIGHT way to do that

marc-andre menard
A: 

what about that solution :

$('#mytable tr').each(function() {
    var customerId = $(this).find("td").eq(2).html();    
}
marc-andre menard
A: 

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.

Paolo Bergantino
A: 

no the basic question is hot to get a selector with $(this)

here is the other question i ask... based on you code (tablerize)

http://stackoverflow.com/questions/656292/table-to-horizontal-bar-graph-in-jquery/656545#656545

marc-andre menard