Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How to minimize the active menu item and close the previous one? - bug-code.com Q&A

How to minimize the active menu item and close the previous one?

0 like 0 dislike
115 views
Hello. Please tell me how to do to have a menu item which is clicked and the previous one was closed? Here page sidebar. There unfolding the categories and sub-categories. Now, if you click on the arrows it opens all, and the need to previously open point closed.

Here is the code of the menu

$('.catalog_aside li').has('ul').addClass('down'); $('.catalog_aside > ul li.down > ul').before(''); $('.catalog_aside .down .btn-dropdown').each(function(){ if($(this).siblings('ul').is(':visible')){ $(this).addClass('active'); } }); $('.catalog_aside .down .btn-dropdown').click(function(){ $(this).parent().toggleClass('open'); if($(this).siblings('ul').is(':visible')){ $(this).siblings('ul').slideUp(); $(this).removeClass('active'); }else{ $(this).siblings('ul').slideDown(); $(this).addClass('active'); } });


Thank you.)
asked by | 115 views

1 Answer

0 like 0 dislike
To close the remaining items before opening a new one:

$('.catalog_aside .down .btn-dropdown').click(function(){ $('.catalog_aside ul ul').css({display: 'none'}) .siblings('.btn-dropdown').removeClass('active') .parent('li').removeClass('open'); $(this).parent().toggleClass('open'); if($(this).siblings('ul').is(':visible')){ $(this).siblings('ul').slideUp(); $(this).removeClass('active'); }else{ $(this).siblings('ul').slideDown(); $(this).addClass('active'); } });
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

12.8k users

24,788 questions
46,220 answers
0 comments
12,813 users