views:

70

answers:

3

I have a table with a dozen rows, one of which is:

<TR><TD>
<B>Order Date</B> </TD><TD> [foo] </TD></TR>

<TR><TD>

and i want to assign the value of the last cell to a var.

thx

A: 

Your question is somewhat unclear.

You can get the last child of a row for which the first child contains Order Date like this:

$('tr:has(td:first-child:contains("Order Date")) td:last-child').text()
SLaks
A: 

try:

var text = $('td:contains("Order Date")').parent().children('td:last').text();
Reigel
This answer works - curious as to why the -1
justSteve
me too.. why -1?...
Reigel
Probably someone is on the ball and sees that it is inefficient going back up to go back down....
redsquare
yup, the nextAll way is 20 func calls less in 1.32 and 15 in 1.4 than back up to parent only to get all the children
redsquare
see http://gyazo.com/a3ef74da7b5380e776ca5e276b70bdff.png
redsquare
lol... should have just explained it. being -1 sounds like it is wrong a wrong answer and would not work... efficiency is not even the topic here, justSteve just asked the "how" only. ;) cheers!
Reigel
and does this mean that SLaks' answer there is faster than mine? :)
Reigel
Riegel - there are hundreds of correct ways of doing things however we are trying to give the 'best' advice here. Hopefully advice that will not make your web page creak at the seams....
redsquare
Reigel - why don't you test it for yourself
redsquare
Well, I get you man. It's just if you do hover on degrade arrow, you can see that is says, "This answer is not useful (click again to undo)". By that, any reader would say, "Ahh this is not useful, why is it marked as check?" I guess my answer was useful it's just it's not the best.
Reigel
Well anyone googling and finding this question ould want to see the best answer not just the correct answer (I am sure you agree). The readers judge the best answer by the only way possible up or down voting. Compared to other answers I guess this answer is not useful! The fact that an answer gets selected as the correct one is a moot point IMO.
redsquare
A: 

cleaner:

  var cellText = $('td:contains("Order Date")').nextAll(':last').text();
redsquare