How to remove HTML <body>
element with all of its content?
var e = document.getElementsByTag('html');
e.removeChild('body');
Does not work.
How to remove HTML <body>
element with all of its content?
var e = document.getElementsByTag('html');
e.removeChild('body');
Does not work.
The simple solution would be
document.body.innerHTML = "";
But why on earth would you want to do this?
By the way:
var e = document.getElementsByTag('html');
should be
var e = document.getElementsByTagName('html')[0];
and
e.removeChild('body');
should be
e.removeChild(document.body);
var e = document.body; e.parentNode.removeChild(e);
… however HTML documents require a body element, so this may have unexpected behavior.
I think this will remove it
var html = document.getElementByTagName('html')[0];
var body = document.getElementByTagName('body')[0];
html.removeChild(body);
document.body.parentNode.removeChild(document.body)
or
document.body = document.createElement("body")
or
while(document.body.childNodes.length != 0) document.body.removeChild(document.body.childNodes[0])