Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all the 'tr' if the any of the 'td' does not have given text

I have a table with many rows . first row is the header.

i want to delete all the rows if any of its td does not have given text.

<tr>
     <td id="1" class="links">Madia</td>
     <td id="" class="edit_client" >Press</td>
</tr>
<tr>
    <td id="2" class="td_link" >Nagara </td>
    <td class="td_link" id="11" class="edit_client">KR Pura</td>
</tr>

I want to delete all the tr , if any of its td does not have given text say "me hussy".

 $('tr').each(function () { 

 });

i do not want delete first row because its header. so function should check from second row onwards.

like image 533
Hussy Avatar asked Jan 20 '26 14:01

Hussy


1 Answers

Try doing this

$('table tr:gt(0)').each(function() {
   if ($('td:contains("me hussy")', this).length == 0) $(this).remove();
});​

Demo on jsFiddle.net

EDIT:

Thanks mesiesta for :gt(0)

EDIT

With respect to OP's comment

var name = "me hussy";
$('table tr:gt(0)').each(function() {
   if ($('td:contains("'+ name +'")', this).length == 0) $(this).remove();
});​
like image 67
Amar Palsapure Avatar answered Jan 23 '26 04:01

Amar Palsapure



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!