jQuery: Removing the jQueryUI dialog elements on close
March 24th, 2010 by jeremychoneBy default, $(..).dialog(”close”) or even $(..).dialog(”destroy”) leaves some html element in the DOM. Could be an issue when you expect to have it removed.
Here is a little trick
$("<div title='my transient dialog'>Some content</div>").dialog({
close: function(event, ui){
// Remove the dialog elements
// Note: this will put the original div element in the dom
$(this).dialog("destroy");
// Remove the left over element (the original div element)
$(this).remove();
}
});
Now, clicking on the close button or calling ‘close’ will remove the dialog elements completely
November 29th, 2010 at 2:44 pm
Thanks!
March 23rd, 2011 at 4:55 pm
Thanks for this snippet. Useful for me when popping a YouTube video player into the dialog. Now when the dialog is closed, the video player is removed as well. Previously, the audio had kept on playing, even though the user couldn’t see the video any longer. Thanks!