I'm searching a js one-liner to delete everything inside the <html>
Tag.
I want to remove the <head>
, the <body>
and everything else declared outside those.
I'm searching a js one-liner to delete everything inside the <html>
Tag.
I want to remove the <head>
, the <body>
and everything else declared outside those.
document.write()
will create empty page, or actually the following code:
<html>
<head></head>
<body></body>
</html>
But I am not sure if this won't clash if the code will be in external file
It's not an oneliner, but it does the job you're asking for.
document.open();
document.write("");
document.close();
1 liner :)
window.onload = function(){ document.getElementsByTagName("html")[0].innerHTML = "";};
Once your HTML page is loaded, the javascript is loaded into the browser memory. So if you are to load jQuery for instance, you can simply call;
$('html').empty();
Give it a try using Google Chrome's Javascript Console. Type the above code, then you can still access jQuery and manipulate the DOM.
Edit
To answer your comment John. You have not stated in your question that jQuery cannot be used.
Not really a good idea, but this worked for me.
First, wrap all the elements in a div element with a id.
I made a div with the id wrapper
.
Then:
let doc = document.getElementById("wrapper");
doc.innerHTML = "";