On click slidetoggle div but hide others first - jQuery

后端 未结 5 1838
太阳男子
太阳男子 2021-02-06 13:06

I have a page that when a user clicks a title, the following div toggles display.

I want to somehow say if any other divs are display:block then set them to display non

5条回答
  •  星月不相逢
    2021-02-06 13:58

    This will close all the open div with animation and opens the required div

    $('.office-title').click(function(){
         var that = $(this);
         if('.office').each(function() {
           if($(this) == $(that).next('div')) {
              $(this).slideToggle();
           }
           else {
              if($(this).css('display')!=='none') {
                 $(this).slideToggle();
              }
           }
         });
         return false;
    });
    

提交回复
热议问题