var header = document.getElementById("header"); var hamburgerMenu = document.getElementById("header-hamburger"); var nav = document.getElementById("header-nav"); header.className += " header-js"; var className = header.className; var oldHamburgerTabIndex = hamburgerMenu.tabIndex; function toggleHamburger() { if (header.className.match(/(?:^| )header-nav-opened( |$)/)) { header.className = className; document.documentElement.style.overflow = null; hamburgerMenu.tabIndex = oldHamburgerTabIndex; } else { header.className += " header-nav-opened"; document.documentElement.style.overflow = "hidden"; hamburgerMenu.tabIndex = 1; } } hamburgerMenu.onclick = toggleHamburger; hamburgerMenu.onkeydown = function (e) { if (e.key == "Enter") toggleHamburger(); }