Skip to content

Instantly share code, notes, and snippets.

@brian-lim-42
Created August 8, 2015 21:31
Show Gist options
  • Save brian-lim-42/e490a926e159b2ae6b84 to your computer and use it in GitHub Desktop.
Save brian-lim-42/e490a926e159b2ae6b84 to your computer and use it in GitHub Desktop.
jQuery UI Open Dialog and Create a Close Button
var modalDialog = $('#dialogDiv').dialog({
autoOpen: false,
open: function () {
// Destroy Close Button (for subsequent opens)
$('#dialog-div-close').remove();
// Create the Close Button (this can be a link, an image etc.)
var link = '<a id="dialog-div-close" href="#" style="float:right;text-decoration:none;">Close</a>';
// Create Close Button
$(this).parent().find(".ui-dialog-titlebar").append(link);
// Add close event handler to link
$('#dialog-div-close').on('click', function () {
modalDialog.dialog('close');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment