如何让jQuery的$ .each()函数根据条件跳过某些对象?

aal*_*aap 3 html javascript jquery

说我有以下HTML:

<p class="link"><a href="#">This is a link.</a></p>
<p class="link"><a href="#">This is another link.</a></p>
<p class="link current"><a href="#">This is yet another link.</a></p>
<p class="link"><a href="#">This is still another link.</a></p>
Run Code Online (Sandbox Code Playgroud)

我想使用jQuery的$.each()函数来遍历类中的所有对象link,但我想跳过也有类的对象current.我怎么做?

我可以像这样检查每个循环中是否存在类:

$('.link').each(function() {
    if (!$(this).hasClass('current'))
        $(this).fadeOut();
})
Run Code Online (Sandbox Code Playgroud)

...但是有没有办法在jQuery中指定"class x,而不是class y",不再需要if条件?

Guf*_*ffa 13

使用:not()选择器排除元素:

$('.link:not(.current)').fadeOut();
Run Code Online (Sandbox Code Playgroud)