qwerty
qwerty

Reputation: 157

Close the dialog box using jquery

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

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337560

Why not just call your HideDialog() function?

$(document).keyup(function(e) {
    if (e.keyCode == 27) {
        HideDialog();
    } // esc
});​

Upvotes: 2

Related Questions