当一个 DIV 打开时关闭所有其他 DIV - 使用单独的关闭按钮

Close all other DIVs while one is open - with separate close button

我有一堆 DIV 可以切换打开和关闭。 它们通过单击 DIV "case-toggle" 打开,并通过名为 "case-close"

的单独范围关闭 DIV 之后显示点击有 class "case-popup"

问题是多个 DIV 可以一次打开,但我只希望一次打开一个 DIV 而其他所有关闭。
我不确定需要什么额外的代码在这里添加以实现这一点。

我搜索了又搜索,但我发现在使用单独的关闭按钮时没有任何效果。

这是代码:

$(document).ready(
    function(){
        $('.case-toggle').click(
            function(){
             $(this).next('.case-popup').show();  
        }
        );

    $('.case-close').click(
        function(){
         $(this).closest('.case-popup').hide();  
        }
        );

}       
);

非常感谢您的帮助!

添加这一行

    $('.case-popup').hide();

$('.case-toggle').click()函数

$(document).ready(
  function() {
    $('.case-toggle').click(
      function() {
        $('.case-popup').hide();
        $(this).next('.case-popup').show();
      }
    );

    $('.case-close').click(
      function() {
        $(this).closest('.case-popup').hide();
      }
    );    
  }
);

这样使用

   $('.case-toggle').on("click", function() {
        $('.case-popup').hide();
        $(this).next('.case-popup').show();
  });