如何从jQuery选择器中排除$(this)? [英] How can I exclude $(this) from a jQuery selector?

查看:109
本文介绍了如何从jQuery选择器中排除$(this)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的东西:

<div class="content">
    <a href="#">A</a>
</div>
<div class="content">
    <a href="#">B</a>
</div>
<div class="content">
    <a href="#">C</a>
</div>

当单击这些链接之一时,我要在未单击的链接上执行.hide()函数.我了解jQuery具有:not选择器,但在这种情况下我不知道如何使用它,因为我必须使用$(".content a")

When one of these links is clicked, I want to perform the .hide() function on the links that are not clicked. I understand jQuery has the :not selector, but I can't figure out how to use it in this case because it is necessary that I select the links using $(".content a")

我想做类似的事情

$(".content a").click(function()
{
    $(".content a:not(this)").hide("slow");
});

但是我不知道在这种情况下如何正确使用:not选择器.

but I can't figure out how to use the :not selector properly in this case.

推荐答案

尝试使用 not() 方法 ,而不是 :not()选择器.

Try using the not() method instead of the :not() selector.

$(".content a").click(function() {
    $(".content a").not(this).hide("slow");
});

这篇关于如何从jQuery选择器中排除$(this)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆