When creating the jQuery UI dialog box, the current versions (1.8. *) Automatically add the dialog to the body.
So, if you do:
$('<div>').dialog({modal: true})
It just works. You have to make sure that you call .remove() when the dialog is closed to remove the new item though!
function myalert(title, text) { var div = $('<div>').html(text).dialog({ title: title, modal: true, close: function() { $(this).dialog('destroy').remove(); }, buttons: [{ text: "Ok", click: function() { $(this).dialog("close"); }}] }) }; myalert("Test", "This is a test modal dialog");
See http://jsfiddle.net/alnitak/G3GRZ/ for a full working demo.
source share