0
$("tr[class*='Row']").each(function(){
    if($(this).hasClass("[class*='Row0']")){
        alert("This one is good boys."); }
        else{
            $(this).remove();
        }       
    });

So maybe there is a better way to do the whole thing but I need to find all the tr classes that has 'Row' inside in it and delete it, except for the class Row0, so I tried doing hasClass, find and so on but I can't seem to make it work because I need to use *=.

TL-DR: I want to delete all the classes that has a Row in it except for Row0. My pseudo-code is up there.

Argus
  • 150
  • 1
  • 10
  • It's `hasClass('Row0');`, no need for `class*=`. – Albzi Feb 24 '16 at 11:36
  • 3
    Why not just `$("tr[class*='Row']").not('.Row0').remove();`?! And to avoid any conflict, you should set as classes e.g `Row-0, Row-1, etc...` and use `[class~=Row]` – A. Wolff Feb 24 '16 at 11:36
  • Delete the row or the class from the row? – StudioTime Feb 24 '16 at 11:38
  • [Here](http://stackoverflow.com/questions/2178416/jquery-using-starts-with-selector-on-individual-class-names) is the solution. Try `$("tr[class^='ROW'])` that will return all `tr` whose class starts with ROW – Braj Feb 24 '16 at 11:38
  • Classes looks like AAAAAAAAAAAAAAAAA_Row0AAAA, so changing A.Wolff's script to this $("tr[class*='Row']").not("tr[class*='Row0']").remove(); just saved me, thank you. Also to answer your question, Wolff, my work uses Bonita BPM software that just creates a bunch of empty Rows for unknown reasons and it blocks the whole page ( Don't ask, I asked seniors at my work what might cause it but noone knows ) So I'll have to use this work-around to delete the classes. – Argus Feb 24 '16 at 11:40

2 Answers2

1

Classes looks like

AAAAAAAAAAAAAAAAA_Row0AAAA,

so changing A.Wolff's script to this $("tr[class*='Row']").not("tr[class*='Row0']").remove(); just saved me, thank you.

Also to answer your question, Wolff, my work uses Bonita BPM software that just creates a bunch of empty Rows for unknown reasons and it blocks the whole page ( Don't ask, I asked seniors at my work what might cause it but noone knows ) So I'll have to use this work-around to delete the classes.

Thank you everyone for answers.

Argus
  • 150
  • 1
  • 10
0

try this

$("tr.Row").each(function() {
  if ($(this).hasClass("Row0")) {
    alert("This one is good boys.");
  } else {
    $(this).remove();
  }
});

or just do it with the simple and easy way

$("tr.Row").not('.Row0').remove()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table style="width:100%">
  <tr class="Row">
    <td>Jill</td>
    <td>Smith</td> 
    <td>50</td>
  </tr>
  <tr class="Row">
    <td>Eve</td>
    <td>Jackson</td> 
    <td>94</td>
  </tr>
  <tr class="Row Row0">
    <td>Eve</td>
    <td>Jackson</td> 
    <td>94</td>
  </tr>
</table>
Jai
  • 74,255
  • 12
  • 74
  • 103
elreeda
  • 4,525
  • 2
  • 18
  • 45