Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove body element

How to remove HTML <body> element with all of its content?

var e = document.getElementsByTag('html');
e.removeChild('body');

Does not work.

like image 356
w00 Avatar asked May 24 '10 19:05

w00


People also ask

How do you remove elements from your body?

To remove the p element from the body , start by coding bodyElement , followed by the removeChild() instruction. Then, remove paragraph from bodyElement by coding paragraph between the parentheses.

What is a body element?

The <body> element contains all the contents of an HTML document, such as headings, paragraphs, images, hyperlinks, tables, lists, etc. Note: There can only be one <body> element in an HTML document.

Can your body replace body elements?

You can only replace the HTML's body element with PHP if you are outputting the HTML with PHP (changing it before outputting it). PHP works server-side, so once the HTML reaches the client it cannot modify it.

How do you remove an element from a child?

Child nodes can be removed from a parent with removeChild(), and a node itself can be removed with remove(). Another method to remove all child of a node is to set it's innerHTML=”” property, it is an empty string which produces the same output.


1 Answers

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);
like image 200
Sean Kinsey Avatar answered Oct 21 '22 14:10

Sean Kinsey