Reputation: 157
Trying to close the box using esc not working
$(document).ready(function() {
$("#btnShowSimple").click(function(e) {
ShowDialog(false);
e.preventDefault();
});
$("#btnShowModal").click(function(e) {
ShowDialog(true);
e.preventDefault();
});
$("#btnClose").click(function(e) {
HideDialog();
e.preventDefault();
});
});
function ShowDialog(modal) {
$("#overlay").show();
$("#dialog").fadeIn(300);
if (modal) {
$("#overlay").unbind("click");
}
else {
$("#overlay").click(function(e) {
HideDialog();
});
}
}
function HideDialog() {
$("#overlay").hide();
$("#dialog").fadeOut(300);
}
$(document).keyup(function(e) {
if (e.keyCode == 27) {
$('.btnClose').click();
} // esc
});
Upvotes: 0
Views: 401
Reputation: 337560
Why not just call your HideDialog()
function?
$(document).keyup(function(e) {
if (e.keyCode == 27) {
HideDialog();
} // esc
});
Upvotes: 2