title: Use Ajax to load/unload modal windows with Twitter Bootstrap
body: <p>I'm using Bootstrap (Version 2.3.1) and I'm using Ajax to load in a modal window. Is there a way to remove the modal window from the DOM when I close the modal window?</p>
  
  <pre><code>$('[data-toggle="modal"]').click(function(e) {
          e.preventDefault();
          var url = $(this).attr('href');
  
          if (url.indexOf('#') == 0) {
           $(url).modal('open');
          } else {
              $.get(url, function(data) {
                  $(data).modal();
              }).success(function() {
                  console.log('success');
  
                  // I tried this below but didn't work
                  // $('#modalClose).on('click',function(){
                  //    $('#myModalWindow').remove();
                  // });
              });
          }
      });
  </code></pre>
  
  <p>My button:</p>
  
  <pre><code>&lt;a href="path/to/modal.html" data-target="#" data-toggle="modal"&gt;Launch modal&lt;/a&gt;
  </code></pre>
  
  <p>In my modal window, I have a close button.</p>
  
  <pre><code>&lt;button class="btn" data-dismiss="modal" aria-hidden="true"&gt;Close&lt;/button&gt;
  </code></pre>
  
  <p>However, when I close the modal, the html is still in the DOM and if I load the modal again, it outputs the HTML again. Is there a way to remove the modal window from the DOM when I close the modal window?</p>