I'm playing around with some selectors, and I'm hitting a wall with selecting Text inside a cell.
Here's a simple attempt I'm making.
<table>
<tr>
<td>First Name</td>
<td>*required</td>
</tr>
</table>
I want to change the class for that cell to be "red" - if the string "*required" is found.
Here's my attempt at the jquery:
$("td:contains('*required')").addClass("red");
It's causing all cells to apply that class, it seems. Any better ways to look for specific text?
What you have works, you can test it here, keep in mind that any parent <td>
also contains that text though, to do an exact match do this:
$("td").filter(function() { return $.text([this]) == '*required'; })
.addClass("red");
You can test it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With