隐藏所有缺少特定类的表行?

问题描述:

我正在使用jQuery的toggleClass()方法来处理表行突出显示,而我想做的就是创建一个函数,该函数将隐藏所有没有 具有"highlight"类的表行已应用.

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

表本身有一个ID(tblTest),每行也有一个ID.但是,在这种情况下,我不太关心ID的问题,而不是是否将"highlight"类应用于该行.基本上遍历每个表行,检查是否应用了"highlight:"类,如果未应用,则应用"hidden"类的最佳方法是什么.

The table itself has an ID (tblTest) and each row has an ID as well. However in this case I don't really care about ID's so much as whether or not the "highlight" class is applied to the row. What is the best approach for essentially walking through each table row, checking to see if the "highlight: class is applied and if it is NOT then apply the "hidden" class.

谢谢

使用jQuery隐藏它们:

To use jQuery to hide them:

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

要应用您的隐藏课程:

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

您通常应该使用 jQuery效果隐藏内容.

You should generally favour the jQuery effects for hiding things however.