diff --git a/static/js/menu.js b/static/js/menu.js index 6c1f350..47b64e3 100644 --- a/static/js/menu.js +++ b/static/js/menu.js @@ -1,11 +1,15 @@ -var toggle = document.getElementById('toggle'); -var menu = document.getElementById('menu'); +const toggle = document.getElementById('toggle'); +const menu = document.getElementById('menu'); -toggle.addEventListener('click', function () { +function toggleMenu() { menu.classList.toggle('main-nav__list--active'); this.classList.toggle('main-nav__btn--active'); this.setAttribute( 'aria-expanded', - this.getAttribute('aria-expanded') === 'true' ? 'false' : 'true' + this.getAttribute('aria-expanded') === 'true' ? 'false' : 'true', ); -}); +} + +if (toggle && menu) { + toggle.addEventListener('click', toggleMenu, false); +}