Skip to content

Instantly share code, notes, and snippets.

@gepser
Created November 13, 2013 01:40
Show Gist options
  • Save gepser/7442128 to your computer and use it in GitHub Desktop.
Save gepser/7442128 to your computer and use it in GitHub Desktop.
Mostrar u ocultar un div con la tecla ESC
//Esta funcion va en el body onload
function CapturadorDeEventos(){
if (window.addEventListener) {
window.addEventListener("keydown", compruebaTecla, false);
} else if (document.attachEvent) {
document.attachEvent("onkeydown", compruebaTecla);
}
}
function compruebaTecla(evt){
var divX = document.getElementById("divParaOcultarMostrar")
var tecla = evt.which || evt.keyCode;
if(tecla == 27){
if (divX.style.display == 'none' ){
divX.style.display = 'block'
}else{
divX.style.display = 'none'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment