I want to completely clear the DOM with Javascript.
I tried several things, for example:
document.getElementsByTagName("html")[0].innerHTML = ""; document.body.innerHTML = "";
Interestingly, clearing the head like this will result in an error ("invalid target element for this operation") in IE, but will successfully clear the head in Chrome. However, body scrubbing like this works in IE but doesn't work in Chrome.
I also tried
document.childNodes.length = 0;
but this is apparently a read-only property and won't do anything.
Is there a good cross browser way to clear the DOM?
Peter Olson
source share