隐藏所有,但$(this)通过:不是在jQueryselect器

高级标题,简单的问题:

我怎么能在jQuery(隐藏除$(this)之外的所有内容)?

 $("table tr").click(function() { $("table tr:not(" + $(this) + ")").hide(); // $(this) is only to illustrate my problem $("table tr").show(); }); 
 $(this).siblings().hide(); 

遍历/兄弟姐妹

 $("table.tr").not(this).hide(); 

顺便说一下,我认为你的意思是$("table tr") (用一个空格而不是一个点)。
你有它的方式,它select每个表有一个类的tr (例如, <table class="tr"> ),这可能不是你想要的。

有关更多信息,请参阅文档 。

如果你想结合not()和其他select器,你可以使用add():

 $('a').click(function(e){ $('a').not(this).add('#someID, .someClass, #someOtherID').animate({'opacity':0}, 800); }); 

这将淡出所有其他的链接,但点击一个,另外淡出一些选定的ID和类。

我认为一个解决scheme可以是这样的:

 $("table.tr").click(function() { $("table.tr:not(" + $(this).attr("id") + "").hide(); // $(this) is only to illustrate my problem $(this).show(); }) 

– EDIT评论:

 $("table.tr").click(function() { $("table.tr:not(#" + $(this).attr("id") + ")").hide(); // $(this) is only to illustrate my problem $(this).show(); })