Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save YakovSPb/9c47c18d902a928a39252d1725300509 to your computer and use it in GitHub Desktop.
Save YakovSPb/9c47c18d902a928a39252d1725300509 to your computer and use it in GitHub Desktop.
Закрытие окна при клике вне его или по нему JS
Закрытие окна при клике вне его или по нему JS
================
document.addEventListener('click', function(e) {
const mobileMenu = document.querySelector('.sub-menu')
if (e.target.hasClass !== 'sub-menu' && (!e.target.matches('.menu-item-has-children') && !e.target.parentElement.matches('.menu-item-has-children'))) {
mobileMenu.classList.remove('open-menu')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment