jquery to loop through table for text comparison
Looping through the table is not a problem.
Looping through the table and do comparison at the same time assigning the other td in same row with different value is a problem. How can this be done ???
- going through #tblView tbody tr.class
- to find through all row for second td and see whether the .text() is "completed"
- if yes
- then third td's span's inner text set to "bingo"
- else
- do nothing
- end
<table id="tblView">
<tbody>
<tr class="class">
<td>completed</td>
<td></td>
<td></td>
</tr>
<tr class="class">
<td>not yet</td>
<td></td>
<td></td>
开发者_开发问答</tr>
</tbody>
</table>
Try -
$("#tblView tbody tr.class").each(function() {
if ($(this).find("td:eq(1)").text() === "completed") $(this).find("td:eq(2)").text('bingo');
})
Demo - http://jsfiddle.net/d45ZQ/1/
精彩评论