jQuery - .not()不起作用

RGB*_*GBK 0 jquery filtering hover

这是我的代码:

$("a").not(".current_page_item").hover(
   function(){
      $(this).stop().animate(
          {color: "#ffffff"}, 'slow'
      );
   },
   function(){
      $(this).stop().animate(
         {color: "#666666"}, 'slow'
      );
   }
);
Run Code Online (Sandbox Code Playgroud)

如果我特别要求CSS更改类,例如:

$(".current_page_item").css("color", "#ff00ff");
Run Code Online (Sandbox Code Playgroud)

我可以改变它的颜色,所以我知道这不是我的错.

有任何想法吗?

Fel*_*ing 5

根据演示页面中的标记,您必须:

$("a").not(".current_page_item > a").hover(...)
Run Code Online (Sandbox Code Playgroud)

或者:

var selected = $('.current_page_item > a')[0];
$("a").not(selected).hover(...);
Run Code Online (Sandbox Code Playgroud)

(可能会更快)

要不就:

$("li").not(".current_page_item").hover(...)
Run Code Online (Sandbox Code Playgroud)

(如果它也改变了链接的颜色,不确定(链接是特殊的;)))

current_page_item是一类父类li,而不是链接本身.

您的代码仅过滤a具有类的链接(元素)current_page_item,但它们都没有,因此它会选择所有链接.