window.onload = function() { (function() { var hamburger = { navToggle: document.querySelector('.nav-toggle'), nav: document.querySelector('.links'), doToggle: function(e) { e.preventDefault(); this.navToggle.classList.toggle('expanded'); this.nav.classList.toggle('expanded'); } }; document.addEventListener('click', function(e) { if (e.target.className.includes("nav-toggle")) { hamburger.doToggle(e); } else { hamburger.navToggle.classList.remove('expanded'); hamburger.nav.classList.remove('expanded'); } }); }()); }