//Code that I have tried but it doesnt work: $('#historyOfStatus table td').not(':contains("Revisions Required – CM")').parents("tr").remove(); <div id="historyOfStatus"> <table> <tbody> <tr> <th>Value</th> <th>Date Time</th> <th>By</th> </tr> <tr> <td class="Data1">Draft</td> <td class="Data1">2022-11-14 13:34:31</td> <td class="Data1">Muhammad Akhtar</td> </tr> <tr> <td class="Data1">Revisions Required – CM</td> <td class="Data1">2022-11-14 13:40:18</td> <td class="Data1">a</td> </tr> <tr> <td class="Data2">Under CFF Contracts Manager Review</td> <td class="Data2">2022-11-14 13:41:38</td> <td class="Data2">aa</td> </tr> <tr> <td class="Data1">Under CFF Compliance Review</td> <td class="Data1">2022-11-14 13:41:43</td> <td class="Data1">aaaa</td> </tr> <tr> <td class="Data2">Revisions Required – CM</td> <td class="Data2">2022-11-14 13:41:48</td> <td class="Data2">bb</td> </tr> <tr> <td class="Data2">Revisions Required – CM</td> <td class="Data2">2022-11-14 13:43:10</td> <td class="Data2">cc</td> </tr> </tbody> </table> </div>
https://jsfiddle.net/Lvgb6r3f/3/ $(document).ready(function() { $("td:contains('Revisions Required – CM')").css("color", "red"); $("td:contains('Revisions Required – CM')").parent().remove() });
Thanks for the reply but my Post is: How can I remove all rows from a table except rows where first cell value contains "Revisions Required – CM"?
I'd just get a list of all the rows and use a for loop to check them and delete. Better still, I'd fix it on the server side so it never even hits the page, that way pagination etc will work better.
This is what it does, it removes tr where that value is present. It's pretty much this line of code $("td:contains('Revisions Required – CM')").parent().remove(). Check this fiddle: https://jsfiddle.net/Lvgb6r3f/3/.
Sorry: text = "Revisions Required – CM"; $('table tr:gt(0)').each(function() { if ($('td:contains("'+text+'")', this).length == 0) $(this).remove(); }); https://jsfiddle.net/k0ybwv3x/1/
Txs for your reply. Hey, your code doesn't work, your code doesn't remove tr if first cell value contains "aaa". Anyways I was looking for the following code: $('#revisionsRequesteHistory table tr').each(function() { if($(this).find('td').first().text() !== 'Revisions Required – CM') this.remove(); });