Please check the below code. Here i'm deleting the row, if that row td contains the value "B". But bellow code is removing all rows.
jQuery
$(document).ready(function() {
$("#mytable tr td:contains('B')").parent().remove();
});
HTML
<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>
To remove the tr
where a td
within it contains ONLY B
var searchString = 'B';
$("#mytable tr td:contains('" + searchString + "')").filter(function() {
return $(this).text().trim() == searchString;
}).parent().remove();
Example fiddle
To remove only the td
which contains a B
:
The parent()
is putting the selector on the tr
, which is then being removed - along with all td
elements. You don't need to use parent()
here.
$("#mytable tr td:contains('B')").remove();
Example fiddle
Sandeep Try this.
$(document).ready(function()
{
$("#mytable td").text(function(index, currentText)
{
if(currentText.trim()=='B')
$(this).parent().remove();
});
});
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