My website features a menu with headings and submenus. The issue arises when users hover over the headings - the submenus fail to show up. Additionally, after clicking on an item in the submenu, the submenu should be hidden using Javascript. However, the hover functionality of the menu is disrupted due to this. I need assistance in resolving this problem.
function closesSan() {
document.getElementsByClassName('submenu')[0].style.setProperty('display', 'none', 'important');
}
#main:hover .submenu {
display: block!important;
}
<ul>
<li id="main">
<a href="javascript:void(0)">List</a>
<ul class="submenu" style="display: none;">
<li onclick="closesSan()">Bacon</li>
<li onclick="closesSan()">Tuna</li>
<li onclick="closesSan()">Chicken</li>
</ul>
</li>
</ul>