In the html table with the jquery search column, get the value and delete the line

advertisements

HTML:

<table class="table" id="myTable">
   <tr>
        <th>Type</th>
        <th>Counter</th>
        <th>Remove</th>
        <th style="display:none;">TypeDistribution</th>
   </tr>
</table>

I add values dynamically properly.

I want to do search and if myValue equals a value in column 3 (TypeDistribution), get the value in the column 1 (Counter) and delete the entire row. Can I do it with jquery and how?

Type is text,
Counter and TypeDistribution are integers,
Remove is button.

Edit:


Here is your answer,

$(document).ready(function(){
    var searchValue = 456; //lets say your value is 456
    $("table tr").each(function(){
       $(this).find('td').each(function(){
          var currentText = $(this).text();

          if(currentText == searchValue){
              $(this).parents('tr').remove();
          }
      });
   });
});

HTML:-

<table class="table" id="myTable">
    <tr>
      <th>Type</th>
      <th>Counter</th>
      <th>Remove</th>
      <th style="display:none;">TypeDistribution</th>
    </tr>
    <tr>
      <td>abc</td>
      <td>def</td>
      <td>ghi</td>
      <td>pqr</td>
    </tr>
    <tr>
      <td>123</td>
      <td>456</td>
      <td>789</td>
      <td>101</td>
    </tr>
</table>