Just save the link that jQuery returns from the .dialog call:
var magic = $('<div>').html("Ta-da!").dialog();
You can then use this link later to open a popup :
$(magic).dialog('open');
or delete it completely (along with its generated .parent wrapper):
$(magic).parent().remove();
You can even delete it when it is closed by creating it using the close parameter (or adding it later):
close: function(ev, ui) { $(this).remove(); }
var magic = null; function createMagic() { magic = $('<div>').html("Ta-da!").dialog({ modal: true, title: 'Not from the DOM', buttons:[{ click: function () { $(this).dialog("close"); }, text: 'Close Me' }], show: false,
<link href="https://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script> <div style='cursor:pointer'> <a onclick="createMagic();">Make a Magic Modal</a> <br/><br/> <a onclick="showMagic();">Show the Magic Modal</a> <br/><br/> <a onclick="killMagic();">Kill the Magic Modal</a> </div> <br/> Magic object is currently: <label id="MagicStatus" style='color:red'></label> <br/> jQUery UI popup wrappers: <label id="MagicPopStatus" style='color:red'></label>
source share