You use the esc key to open the menu with keycode 27 but how can i make the menu close using the same key esc* aka keycode 27 instead of having to click outside the menu. Do I have to make another event to close menu?
document.head.appendChild(styleItem1);
document.addEventListener('keydown', function(e) {
if (e.keyCode == 27){
if (modal.style.display = "none") {
modal.style.display = "block";
} else {
modal.style.display = "none";
}
}
})
var modal = document.getElementById("simpleModal");
var closeBtn = document.getElementsByClassName('closeBtn')[0];
closeBtn.addEventListener('click', closeModal);
window.addEventListener('click', outsideClick);
function closeModal() {
modal.style.display = 'none';
}
function outsideClick(e) {
if (e.target == modal) {
modal.style.display = 'none';
}
}