title: Javascript Clear DOM
body: <p>I am wanting to completely clear the DOM with Javascript.</p>
  
  <p>I have tried a few things, like this:</p>
  
  <pre><code>document.getElementsByTagName("html")[0].innerHTML = "";
  document.body.innerHTML = "";
  </code></pre>
  
  <p>Interestingly, clearing the head like this will generate an error ("invalid target element for this operation") in IE, but will successfully clear the head in Chrome. However, clearing the body like this works in IE but fails silently in Chrome.</p>
  
  <p>I have also tried</p>
  
  <pre><code>document.childNodes.length = 0;
  </code></pre>
  
  <p>but this is apparently a read-only property and won't do anything.</p>
  
  <p>Is there a good cross-browser way to clear the DOM?</p>