首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >隐藏除$(this) via以外的所有内容:不在jQuery选择器中

隐藏除$(this) via以外的所有内容:不在jQuery选择器中
EN

Stack Overflow用户
提问于 2009-08-25 13:35:20
回答 3查看 90.8K关注 0票数 98

高级标题,简单问题:

如何在jQuery中执行以下操作(隐藏除$(this)之外的所有内容)?

代码语言:javascript
复制
$("table tr").click(function() {
    $("table tr:not(" + $(this) + ")").hide();
    // $(this) is only to illustrate my problem

    $("table tr").show();
});
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-08-25 13:37:18

代码语言:javascript
复制
$(this).siblings().hide();

Traversing/Siblings

票数 193
EN

Stack Overflow用户

发布于 2014-02-07 20:50:55

如果您想将not()与其他一些选择器结合使用,您可以使用add():

代码语言:javascript
复制
$('a').click(function(e){
  $('a').not(this).add('#someID, .someClass, #someOtherID').animate({'opacity':0}, 800);
});

这将淡出所有其他链接,但单击的链接除外,并另外淡出一些选定的ids和类。

票数 6
EN

Stack Overflow用户

发布于 2009-08-25 13:48:33

我认为解决方案可以是这样的:

代码语言:javascript
复制
$("table.tr").click(function() {
    $("table.tr:not(" + $(this).attr("id") + "").hide(); // $(this) is only to illustrate my problem
    $(this).show();
})

--编辑备注:

代码语言:javascript
复制
$("table.tr").click(function() {
    $("table.tr:not(#" + $(this).attr("id") + ")").hide(); // $(this) is only to illustrate my problem
    $(this).show();
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1328314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档