Javascript 使用Jquery显示/隐藏两个div

Javascript 使用Jquery显示/隐藏两个div,javascript,jquery,jquery-selectors,Javascript,Jquery,Jquery Selectors,我有两个部门: <a href="#" class="component_expand"></a> <div class="component_wrapper"> </div> <a href="#" class="component_expand"></a> <div class="component_wrapper">

我有两个部门:

         <a href="#" class="component_expand"></a>
        <div class="component_wrapper">

        </div>

         <a href="#" class="component_expand"></a>
        <div class="component_wrapper">

        </div>

Jquery代码:

<script type="text/javascript">

    $(document).ready(function(){

    $(".component_wrapper").hide();
    $(".component_expand").show();

    $('.component_expand').click(function(){
    $(".component_wrapper").slideToggle();
    });

  });

  </script>

$(文档).ready(函数(){
$(“.component_wrapper”).hide();
$(“.component_expand”).show();
$('.component_expand')。单击(函数(){
$(“.component_wrapper”).slideToggle();
});
});
每次单击“组件展开”打开一个DIV时,我都会尝试。现在打开两个
我很高兴他们能为我提供帮助

您需要使选择器具体化,请使用

尝试:


使用此和
的实例。下一步

$('.component_expand').click(function(){
    $(this).next(".component_wrapper").slideToggle();
});

它几乎可以工作了,我在DIV@allpnay Use next()之前有另一个按钮。next()我需要在DIV打开时将arrow改为up,在DIV关闭时将arrow改为down
 $(document).ready(function(){
    $(".component_wrapper").hide(); //You can do this using css rule itself
    $(".component_expand").show().click(function(){
        $(this).next().slideToggle();
    });
  });
$('.component_expand').click(function(){
    $(this).next(".component_wrapper").slideToggle();
});