window.addEventListener('load', function() { var links = document.getElementById("links").children[0].children; var home = document.getElementsByClassName("home"); var directions = []; for(var i = 0; i < links.length - 1; i++) { directions.push(links[i]); } for(var i = 0; i < home.length; i++) { directions.push(home[i]); } var menu = document.getElementById("menu"); var menuLoc = parseInt(getComputedStyle(menu).getPropertyValue("top")); for(var i = 0; i < directions.length; i++) { directions[i].children[0].onclick = function(event) { event.preventDefault(); var node = event.currentTarget; if(menuLoc != 10) { menuLoc = 0; menu.setAttribute("class", "top"); window.history.pushState("object or string", "Title", node.href); } else { window.history.pushState("object or string", "Title", node.href); } }; } }, false);