I have a simple setup where I have a collapsed menu. When you click on the button, it will open a menu. If the menu is already opened and you open another menu, the previous menu will collapse. All that works. The only thing I noticed is that It will not collapse the opened menu if I click the same button. That menu will only collapse if I open a different menu. I was wondering how the code below will look with that extra function added?
Here's the code for that.
<h5 class="mobile-collapse__title">Title Button</h5>
<div class="mobile-collapse__content">
<ul>
<li>list 1</li>
<li>list 2</li>
<li>list 3</li>
</ul>
</div>
<script>
$(document).ready(function($){
$(".mobile-collapse__title").click(function(e) {
e.preventDefault();
$('.mobile-collapse__content:visible').hide();
$(this).next('div.mobile-collapse__content').show();
});
});
</script>