I have a table and I need to remove all rows that don't contain a string.
$(document).ready(function() {
var str = "b";
$("#mytable tr td:not(:contains(str))").parent().remove();
});
//this doesn't work
<table border="0" align="center" width="45%" cellpadding="2" cellspacing="2" id="mytable">
<tr>
<td align="center" width="15%">A</td>
<td align="center" width="15%">B</td>
<td align="center" width="15%">C</td>
</tr>
<tr>
<td align="center" width="15%">AA</td>
<td align="center" width="15%">BB</td>
<td align="center" width="15%">CC</td>
</tr>
<tr>
<td align="center" width="15%">AAA</td>
<td align="center" width="15%">BBB</td>
<td align="center" width="15%">CCC</td>
</tr>
</table>
I need to only keep the rows where the td text exactly matches the string. What i'm getting is either all rows being deleted, no rows being deleted, or rows being deleted except those that contain "B", "BB", or "BBB". Perhaps "contains" isn't the correct way to do this?