tags:

views:

33

answers:

3
S/N     Name        Result      Action
--------------------------------------
1       Mike        Passed      
2       Mark        Failed      
3       Mary        Failed  

Based on the table above, I need to:

  • Highlight result column in red where the result is Failed
  • Provide a "Retry" hyperlink in action column for those have failed.

Something like $('table.td.result).. (I am not sure about the correct syntax).

+2  A: 

You can use :contains() for example:

$("#myTable td:nth-child(3):contains('Failed')").addClass("failed")
       .next().append("<a href='#'>Retry</a>");

You can try it out here. The :nth-child() part is so we're only looking in the third column, and someone named "Little Bobby Failed" doesn't cause a match in the second column by mistake.

Nick Craver
Cool~ your code is elegant and you beat the rest in speed!
A: 
$("table td:contains('Failed')").css('background-color','red').next('td').append("<a href='http://www.example.com'&gt;Retry&lt;/a&gt;");

See http://jsfiddle.net/adamzr/rZGUc/

Adam
Thanks for your help! :)
A: 

Hi,

to select in which you have the "Failed" text, you can use this selector :

$("td:contains('Failed')")

Arnaud F.
Thanks for your help! :)