title: JQuery dialog show HTML content and prevent removing HTML after dialog is closed?
body: <p>I have been working on Single page application for the past few days. One of the problems that I'm facing is related to JQuery dialog box. I would like to display my forms in JQuery dialog box. There is a few different screens and each of them have different form. User will click on Add or Edit button. I'm passing div id and that content should appear in the dialog box. Each div has unique id and each div has different form inside. Here is my code that creates JQuery dialog box:</p>
  
  <p>JQuery dialog:</p>
  
  <pre><code>var dialogDiv;
  $.extend({ 
      alert: function (message, title, height, width, print) {
          var dialogButtons = {
              "Ok": function() {
                  message.hide();
                  $(this).dialog("close");
              }
          };
  
          if (print) dialogButtons.Print = function() {
              $(this).dialog().printArea();
          };
  
          if (!dialogDiv) {
              dialogDiv = $("&lt;div&gt;"); 
          }   
          dialogDiv.dialog( {
              buttons: dialogButtons,
              resizable: false,
              title: title,
              modal: true,
              width: height,
              height: width,
              overflow:"auto",
              position: {
                      my: "center",
                      at: "center",
                      of: window
              }
          }).html(message);
      }
  });
  </code></pre>
  
  <p>Here is example of my div containers for different forms:</p>
  
  <pre><code>//Form 1
  &lt;div id="myForm1" class="frmLayout"&gt;
      &lt;form name="frmUser" id="frmUser" method="POST" action="#"&gt;
          &lt;fieldset&gt;
              &lt;legend&gt;User Info&lt;/legend&gt;
              &lt;div class="formItem"&gt;
                  &lt;span class="required" style="color:red;"&gt;&lt;b&gt;Required Fields&lt;/b&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="formItem"&gt;
                  &lt;label for="last_name" class="required"&gt;Last Name:&lt;/label&gt;
                  &lt;input type="text" name="ur_lname" id="ur_lname" value="" size="20" maxlength="30" /&gt;
              &lt;/div&gt;
              &lt;div class="formItem"&gt;
                  &lt;label for="first_name" class="required"&gt;First Name:&lt;/label&gt;
                  &lt;input type="text" name="ur_fname" id="ur_fname" value="" size="20" maxlength="30" /&gt;
              &lt;/div&gt;
              &lt;div class="formItem"&gt;
                  &lt;label for="dob" class="required"&gt;DOB:&lt;/label&gt;
                  &lt;input type="text" name="ur_dob" id="ur_dob" value="" size="10" maxlength="10" /&gt;
              &lt;/div&gt;
              &lt;div class="formItem"&gt;
                  &lt;p align="center"&gt;&lt;input type="button" name="urSubmit" id="urSubmit" value="Submit"&gt;&lt;/p&gt;
              &lt;/div&gt;
          &lt;/fieldset&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  
  //Form 2
  &lt;div id="myForm2" class="frmLayout"&gt;
          &lt;form name="frmVehicle" id="frmVehicle" method="POST" action="#"&gt;
              &lt;fieldset&gt;
                  &lt;legend&gt;Vehicle Info&lt;/legend&gt;
                  &lt;div class="formItem"&gt;
                      &lt;span class="required" style="color:red;"&gt;&lt;b&gt;Required Fields&lt;/b&gt;&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;div class="formItem"&gt;
                      &lt;label for="name" class="required"&gt;Name:&lt;/label&gt;
                      &lt;input type="text" name="ur_name" id="ur_name" value="" size="20" maxlength="30" /&gt;
                  &lt;/div&gt;
                  &lt;div class="formItem"&gt;
                      &lt;label for="model" class="required"&gt;Model:&lt;/label&gt;
                      &lt;input type="text" name="ur_model" id="ur_model" value="" size="20" maxlength="30" /&gt;
                  &lt;/div&gt;
                  &lt;div class="formItem"&gt;
                      &lt;p align="center"&gt;&lt;input type="button" name="urSubmitV" id="urSubmitV" value="Submit"&gt;&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/fieldset&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>...Form 3 and Form 4 similar.</p>
  
  <p>Once user access home page all HTML content is loaded and set to <code>display:none</code>. Here is example how this content will be displayed in dialog box:</p>
  
  <pre><code>$('input[name="my button name"]').on('click', function formSubmit(){
      var tabID = $('#tabID').val(); //each tab on my home page has unique id. Current tab value is set to hidden field.
      var divID = $('#'+tabID+'Form'); //This line of code will select correct form
      $.alert(divID.show(),'Form Input',800,600); //here I show the content
  });
  </code></pre>
  
  <p>Problem with this code is that divID content is wiped out from the page once I close my dialog box. For example I will click on Add button on my first tab. Form 1 will show in dialog box. Once I go to tab 2 and click and show Form 2 then go back to tab 1 and try to click on the Add button I will get blank page in my JQuery dialog box. For some reason previous content is removed from the page.
  I'm wondering how I can work around this problem and what is the best solution? Should I some how make a copy of my HTML content before I display in JQuery dialog or there is a better way to do this? If anyone can help or have any example please let me know.</p>
  
  <p>Thank you.</p>