S. Smith S. Smith - 1 year ago 46
jQuery Question

How would I hide a table row if its <td> elements don't have one of two classes?

I need to hide all of the rows in a particular table whose td elements do not contain one of two classes.

If at least one of the td elements in a row contains one of these two classes, then don't hide it. Otherwise, hide the entire row.


Any ideas?

Answer Source

Without an example it's difficult to know exactly what you are looking for, but perhaps something like this would work (air code):

$('#mytable tr').each(function() {
    var count = $('td.class1, td.class2', $(this)).length;
    if (!count) {