关闭其他打开的div当切换其中一个div

关闭其他打开的div当切换其中一个div

问题描述:

我有多个按钮.expandable-container-mobile类。关闭其他打开的div当切换其中一个div

当我切换按钮时,它会展开。

目前,当我打开另一个div先前打开的div不会关闭,但我试图关闭其他部分,下面是我的代码:

$(".expandable-container-mobile").click(function() { 
    $(this).children('.mobile-show-section').stop().slideToggle(700); 
    $(this).not.('.mobile-show-section').stop().slideUp(); 
}); 

HTML代码如下:PHP代码会生成行和按钮:

<div class="expandable-container-mobile"> 
         <div class="expandable" id="<?php echo strtolower($actual_post_title); ?>-expandable"> 
          <div class="activator"> 
           <div class="section-title" id="<?php echo strtolower($actual_post_title); ?>"><?php echo $actual_post_title; ?></div> 
          </div> 
         </div> 
         <div class="mobile-show-section"> 
          <?php       
           $args = array(
            'sort_order' => 'asc', 
            'sort_column' => 'post_date', 
            'child_of' => $id 
           ); 

           $children = get_pages($args); 

           $children_ids = array(); 
           if (! empty($children)) 
            foreach ($children as $post) 
             $children_ids[] = $post->ID; 

           $arrlength = count($children_ids); 

           for($x = 0; $x < $arrlength; $x++) { 
           ?> 
            <a href="<?php echo get_permalink($children_ids[$x]); ?>"><?php echo get_the_title($children_ids[$x]); ?> </a> 
           <?php            
           }  
          ?> 
         </div> 
        </div> 
+0

您有一个额外的点'$(this).not。('。mobile-show-section')。stop()。slideUp();'应该是$(this ).not('。mobile-show-section')。stop()。slideUp();' – Razzildinho

+0

你能提供html代码吗? – Redrif

+0

按钮其实是。激活剂类 – zacwhyyy

您的代码切换所有的孩子一个第二行效果基本show的.expandable-container-mobile不是.mobile-show-section

尝试类似:

var el = $(this).find('.mobile-show-section');//get the current element 
el.stop().slideToggle(700);//toggle the current one 
$('.mobile-show-section').not(el).stop().slideUp();//hide the rest 
+1

辉煌!像魅力一样工作:)感谢队友! – zacwhyyy

+0

@zacwhyyy毕业生有帮助,不要忘记绿色复选框:) – madalinivascu

+1

肯定会标记为一旦启用滴答:)解决方案 – zacwhyyy