How to delete a cell with a value of 3?

<table id="history"> <tr class="row"> <th class="nyr">SteamID</th> </tr> <tr class="row"> <td class="cellHis">1</td> <td class="cellHid">2</td> </tr> <tr class="row"> <td class="cellHis">3</td> <td class="cellHid">4</td> </tr> </table> 

    3 answers 3

    Like this. You just need to take elements with the class cellHis . Cycle through them. and if the text is exactly 3 then delete the current one.

     $(document).ready(function(){ $('.cellHis').each(function( index ) { if($( this ).text() == '3'){ $( this ).remove(); } }); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="history"> <tr class="row"> <th class="nyr">SteamID</th> </tr> <tr class="row"> <td class="cellHis">1</td> <td class="cellHid">2</td> </tr> <tr class="row"> <td class="cellHis">3</td> <td class="cellHid">4</td> </tr> </table> 

      Then through .filter() .

       $("#history .row td").filter(function() { return $(this).text() === "3"; }).remove(); 
       <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="history"> <tr class="row"> <th class="nyr">SteamID</th> </tr> <tr class="row"> <td class="cellHis">1</td> <td class="cellHid">2</td> </tr> <tr class="row"> <td class="cellHis">3</td> <td class="cellHid">4</td> </tr> </table> 

        It's all right ?

         $("#history .row").find("td:contains('3')").remove(); 
         <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="history"> <tr class="row"> <th class="nyr">SteamID</th> </tr> <tr class="row"> <td class="cellHis">1</td> <td class="cellHid">2</td> </tr> <tr class="row"> <td class="cellHis">3</td> <td class="cellHid">4</td> </tr> </table> 

        • And if the value is stored in a variable? Can I contact $("#history .row").find("td:contains(${id})").remove(); ? - MegaRoks
        • @klifort contains('3') - this is wrong .... привет3раза can be written привет3раза and this cell will be deleted - Alexey Shimansky
        • @MegaRoks variable is possible, but the answer is incorrect. PTC ↑ - Alexey Shimansky
        • The answer is written as a question. Perhaps not all the possibilities and covers, but solves the problem that is written - klifort
        • @klifort in the question is quite clearly written that со значением 3 , and not содержащее значение 3 - Alexey Shimansky