user1177518
user1177518

Reputation:

jQuery UI - How to remove dynamic element after dialog closes?

I'm using dialog in my asp.net app, replacing of previously used 'window.showModalDialog' whats why have to load .aspx pages in to iframe.

I want element inside dialog (that contains the iframe) to be created dynamically, and after closing - I want dynamic element (and its content) to be removed.

$('#dialog_link').click(function () {
  $('<div id="dialog" ><iframe src="Default.aspx"></iframe></div>').dialog(
   {
      width: 200,
      height: 200,
      modal:true,
      open: function () { }, 
      close: function () {
        $(this).remove();//have do destroy dynamic element
      }   
   })

   return false;
});

is it right way to do it?

Upvotes: 4

Views: 5062

Answers (3)

Sameera Thilakasiri
Sameera Thilakasiri

Reputation: 9508

close: function () {
   $(this).remove();//have do destroy dynamic element
}

This will work fine. The .remove() call will cause the dialog to be destroyed automatically before it is removed.

Upvotes: 6

ShankarSangoli
ShankarSangoli

Reputation: 69905

Yes, you are doing it correct. remove will take care of destroying the dialog box.

Upvotes: 2

eppdog
eppdog

Reputation: 423

I have had success with the following in my close callback:

$(this).destroy()

Upvotes: 0

Related Questions