jQuery: Bind and unbind the Esc key
Friday, February 4th, 2011Let’s say you want to allow your dialog boxes to be close when the user press “esc.”
$("body").bind("keyup.myDialog", function(event){
// 27 == "esc"
if (event.which == 27) {
// TODO: close the dialog
// unbind the event
$("body").unbind("keyup.myDialog");
}
});