title: How to empty loaded external page including its script inside div using javascript or jquery
body: <p>I was able to load external pages inside a div for first call. But this external page <code>contains .js</code> too, so all of it is included in the process. Now, for the second time I am about to reload it again with the same external page. I get an error Uncaught <code>TypeError: Cannot set property 'innerHTML' of undefined</code>. And I've seen as it is trying to load the same plugins again from that external page. </p>
  
  <p>This is my code that loads the external page</p>
  
  <pre><code>LoadMap($("#map"), "maps/MyExternalPAge.aspx");
  
  function LoadMap(map_param,map_url)
  {
      setTimeout(function () {
          var ajax_load = "";
          map_param.html(ajax_load).load(map_url, function (response, status, xhr) {
              if (status == "error") {
                  var msg = "Sorry but there was an error: ";
                  map_param.html(msg + xhr.status + " " + xhr.statusText);
          }
       });
      }, 1000);
  }
  </code></pre>
  
  <p>And this is how I call that function</p>
  
  <pre><code>LoadMap($("#parent"), "maps/MyExternalPAge.aspx");
  </code></pre>
  
  <p>This is the markup of div</p>
  
  <pre><code>&lt;div id="parent" style="width:100%; height:100%"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>I've tried using <code>empty()</code> and <code>html()</code> but no luck. Please help me guys. Thanks.</p>