Reputation: 205
I have this html-table:
<table id=mytable>
<tr>
<td>
Mark
</td>
<td>
Susan
</td>
</tr>
</table>
Somewhere from javascript an event occur and I can will be able to fetch the name, which is one of those in the table. From javascript/jquery I need to find the td-element containing the name and color it. I tried with:
$("#mytable").find("td:contains('Mark')").parent().css('background-color', 'red');
But the td-element doesnt get colored.
Upvotes: 1
Views: 67
Reputation: 87073
I believe you need to try this:
$("#mytable").find("td:contains('Mark')").css('background-color', 'red');
OR
$("#mytable td:contains('Mark')").css('background-color', 'red');
Upvotes: 1
Reputation: 11137
You already selected the td
what you did is you tried to add a color to the tr
which is the parent of the selected td
:
$("#mytable").find("td:contains('Mark')").css('background-color', 'red');
that's why you example should be highlighting both td
as the color applied for the tr
Upvotes: 0