S. Smith S. Smith - 2 months ago 6
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.

class='class1'
class='class2'
id='mytable'


Any ideas?

MJH MJH
Answer

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) {
        $(this).hide();
    }
});
Comments