Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The following couple of commands will clear out all the HTML and any CSS style sheetsThis first command will create a new body element.

Code Block
languagejs
document.body = document.createElement('body'); // This creates a new body element
document.head

We still have the head element with any styling that is present. You can see this by putting in some simple markup:

Code Block
languagejs
document.body.innerHTML = '';<h1>A                   // This clears the head elementheading</h1><div class="BLOCKone">Block</div>';

You will probably see that the heading is styled in the way that the website you are looking at styles headings.

We can clear that out using:

Code Block
languagejs
document.head.innerHTML = ''

One is still left with any Javascript code which is present. Haven’t found thought of an easy way to clear that yet.

Here’s the lot in one easy code fragment to copy paste into the Javascript console:

Code Block
languagejs
document.body = document.createElement('body'); 
document.body.innerHTML = '<h1>A heading</h1><div class="BLOCKone">Block</div>';
document.head.innerHTML = ''