在多个实例中应用Jquery

在多个实例中应用Jquery,jquery,css,hover,Jquery,Css,Hover,我有一个悬停函数(见下面的代码),它在我应用它的类上提供一个文本的下拉段落。这在指定的类上运行良好 $('.job_container').hover(function(){ $(".job_subheading").animate({top: "30px }, 200);}, function(){ $(".job_subheading").animate({ top: "0px" }, 200); }); 然而,我想用不

我有一个悬停函数(见下面的代码),它在我应用它的类上提供一个文本的下拉段落。这在指定的类上运行良好

$('.job_container').hover(function(){
   $(".job_subheading").animate({top: "30px }, 200);},
      function(){
            $(".job_subheading").animate({
        top: "0px" }, 200);
      });
然而,我想用不同的下拉段落添加更多这些类的实例。当我这样做,然后将鼠标悬停在一个上时,下拉列表将应用于所有对象,因为它们具有相同的类

我是否应该将类更改为ids,并为我希望使用的每个实例重新编写代码? 在多个实例中应用代码最简单的方法是什么

谢谢你的帮助,
Gavin

您应该使用子项选择器:

$('.job_container').hover(function(){
$(this).children(".job_subheading").animate({
top: "30px }, 200);},
                      function(){
$(this).children(".job_subheading").animate({
top: "0px" }, 200);
因此,您的html必须如下所示:

<div class="job_container"><div class="job_subheading"></div>something else</div>
<div class="job_container"><div class="job_subheading"></div>something else</div>
<div class="job_container"><div class="job_subheading"></div>something else</div>
还有别的吗
别的
别的

.job\u副标题是.job\u容器的子元素?很好!(你可以邮寄)