jQuery同时选择'this'和另一个选择器

mtw*_*let 18 jquery css-selectors jquery-selectors

我正在使用jQuery单击功能,并想知道我是否可以使用术语'this'来选择导航元素和另一个选择器同时在这里我的代码:

$('#nav').click(function() {
    $(this, '#anotherSelector').hide();
});
Run Code Online (Sandbox Code Playgroud)

这不起作用.它也选择#anotherSelector而不是#nav元素.我究竟做错了什么?

提前谢谢了.

Nic*_*ver 33

使用.add()另一个选择添加到您的设置要处理,像这样的内容:

$('#nav').click(function() {
    $(this).add('#anotherSelector').hide();
});
Run Code Online (Sandbox Code Playgroud)


Mat*_*att 5

$(this).add('#anotherSelector').hide();改用.

添加

你现在所拥有的内容是"搜索DOM元素(this),它位于ID为anotherSelector的元素内部."; 请看这里了解更多信息.