Hide all table rows that don't have a specific class?

I am using jQuery's toggleClass () method to handle row highlighting in a table, and what I would like to do is create a function that will hide all table rows that do not have a highlight class.

The table itself has an ID (tblTest) and each row has an ID as well. However, in this case, I really don't care about the ID, since the "highlight" class is applied to the string. What is the best approach to essentially step through each row of the table, checking if the "highlight: class" is being applied and if it is NOT using the "hidden" class.

Thank,

+2


source to share


2 answers


To use jQuery to hide them:

$("#tblTest tr:not(.highlight)").hide();

      

To apply your hidden class:



$("#tblTest tr:not(.highlight)").addClass("hidden");

      

You usually prefer jQuery effects for hiding things.

+5


source


$('#tblTest tr:not(:has(.highlight))').slideUp('fast');

      



0


source







All Articles