There is a button with a menu
<button class="show-menu" style="display: flex; align-items: center;"> <h3>Помощь</h3> </button> <ul class="menu menu--hide"> <li class="menu__item" style="display: flex; align-items: center;" > <p>Тест</p> </li> <li class="open-record-panel-btn menu__item" style="display: flex; align-items: center;" > <p>Тест2</p> </li> </ul> And such a code that hangs an event (hides it opens), but it works when clicked, but with focus. Tell me how to make the button work with the focus, and when you click on another area of the menu, it hides
var linkBtn = document.querySelector('.show-menu'); if (linkBtn) { linkBtn.addEventListener('click', function(event) { event.preventDefault(); var menuList = document.querySelector('.menu--hide'); if(menuList) { menuList.classList.toggle('menu--show'); } }); }