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

0 like 0 dislike
47 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 | 47 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

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
24,509 questions
45,931 answers
0 comments
257 users