Satch3000
Satch3000

Reputation: 49384

JQuery Dialog - Replace Timeout with close button

I am using the code below and decided I want a close button instead of the timeout.

How can I replace the timeout with a close button with the code below?

<script type="text/javascript">
$(document).ready(function() {
    $("#info_box").dialog({
        autoOpen: false,
        modal: true,
            width: 400,
            zIndex: 9999999,
        resizable: false,
        open: function() {
            // close the dialog 10 secs after it's opened
            setTimeout(function() {
                $(this).dialog("close");
            }, 10000);
        }
    });

    $(".notavailable").bind("click", function() {
        $("#info_box").dialog("open");
    });
});

</script>

Upvotes: 0

Views: 379

Answers (1)

jabclab
jabclab

Reputation: 15042

You just need to add a buttons property to the Object the dialog is created with, something like:

$("#info_box").dialog({
    autoOpen: false,
    modal: true,
    width: 400,
    zIndex: 9999999,
    resizable: false,
    buttons: [
        {
            text: "Close",
            click: function () {
                $(this).dialog("close");
            }
        }
    ]
});

Upvotes: 3

Related Questions