tags:

views:

43

answers:

2

I want to create a jQuery dialog from HTML returned by an AJAX call. This works, but "destroying" the dialog doesn't remove the content from the div. What is the best way to completely remove the content?

Dialog creation code

$.get( 'mysite/dialogcontent', null,
    function(data)
    {
        $(data).dialog( {
            buttons: { 'OK' : function() { $(this).dialog('destroy'); } }
        } );
    } );

Possible solutions

  1. Manually find and remove the div after calling .dialog('destroy')?
  2. Extend the destroy method and have my version simply remove the elements from the DOM?
  3. Write a new method (kill?) that would do this.
+1  A: 

I think calling remove() on div that the dialog is created from should be the simplest one.

Adam Kiss
Hmm, that's actually simpler than I thought when I originally posted. $(this).dialog('destroy').remove() did the trick.
MikeWyatt
Simple solutions make life nicer :]
Adam Kiss
A: 

You want to remove the div contents but leave the div itself? $(#mydiv).html("") will empty it out.

monksp