<table style="width: 50%" id="myTable">
<tbody>
<tr><td>Row 1</td><td>dd</td><td>red</td><td>dd</td></tr>
<tr><td>Row 2</td><td>dd</td><td>green</td><td>dd</td></tr>
<tr><td>Row 3</td><td>dd</td><td>red</td><td>dd</td></tr>
</tbody>
</table>
<a href="#" name="addRow">Add Row</a>
$(document).ready(function () {
$("a[name=addRow]").click(function() {
$("table#myTable tr:last").after('<tr><td>Row 4</td><td>dd</td><td>red</td><td>dd</td></tr>');
return false;
});
$('#myTable tbody tr td').each(function()
{
if ($(this).text() == 'red')
{
$(this).parent().css('background-color', 'red');
}
else if ($(this).text() == 'green')
{
$(this).parent().css('background-color', 'green');
}
});
});
why does this code not work when adding new rows? I have tried using the live function:
$('#myTable tbody tr td').live('each', function()
but unfortunately, it did not solve the issue.