My code is functioning well, however there is a slight issue with the submenus. When I click on submenu A it opens perfectly, but if I then click on submenu B, A remains open and now both are displayed. I would like for B to close automatically when I click on A.
$(document).ready(function() {
$('.submenu').hide();
$("li:has(ul)").click(function() {
$("ul", this).toggle('slow');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li><a href="link">Menu</a></li>
<li><a href="link">Menu</a></li>
<li>
<ul class="submenu">
<li><a href="link">Menu</a></li>
<li><a href="link">Menu</a></li>
</ul>
</li>
<li>
<ul class="submenu">
<li><a href="link">Menu</a></li>
<li><a href="link">Menu</a></li>
</ul>
</li>
<li><a href="link">Menu</a></li>
</ul>