jQuery:麻烦遍历

sup*_*led 2 jquery

我试图找到一些关于遍历jQuery的体面文档,但是没有找到合适的资源,任何建议都会非常感激.

我正在尝试为菜单创建一个简单的动画.

我有一个简单的菜单:

<ul class='contentNav'>
 <li><a href='#'>One</a>
 <li><a href='#'>Two</a>
 <li><a href='#'>Three</a>
 <li><a href='#'>Four</a>
</ul>
Run Code Online (Sandbox Code Playgroud)

还有一个简单的jquery函数来改变标签的背景颜色:

$(document).ready(function(){

   $(".contentNav a").hoverIntent(
   function(over) {
     $(this).animate({backgroundColor: "#844"}, "fast");
     $(this).parent().find("li a").animate({backgroundColor: "#090"}, "fast");
   },
   function(out) {
     $(this).animate({backgroundColor: "#000"}, "fast");
     $(this).parent().find("li a").animate({backgroundColor: "#000"}, "fast");
   });
}); 
Run Code Online (Sandbox Code Playgroud)

麻烦在于:

$(this).parent().find("li a").animate({backgroundColor: "#090"}, "fast"); 
$(this).parent().find("li a").animate({backgroundColor: "#000"}, "fast");
Run Code Online (Sandbox Code Playgroud)

我试图选择当前没有悬停的所有链接标记项并设置其背景颜色.我该怎么做呢.

谢谢.


UPDATE


我已经采取了所有建议并提出以下代码:

$(this).parent().parent().find("a").not(this).animate({backgroundcolor: "#555"}, 100)
Run Code Online (Sandbox Code Playgroud)

ric*_*age 6

你的行缺少一个额外的父母:

$(this).parent().parent().find("li a").animate({backgroundColor: "#090"}, "fast"); 
$(this).parent().parent().find("li a").animate({backgroundColor: "#000"}, "fast");
Run Code Online (Sandbox Code Playgroud)

由于您的初始选择器位于"a"标记上,因此您希望一次转到"li"标记,然后再转到包含div,如果您想使用find("li a")选择器.