Get the HTML content of the current document:
var x = document.body.innerHTML;
Click the button to display the HTML content of the document.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*w w w. ja va 2 s . c o m*/ var x = document.body.innerHTML; document.getElementById("demo").innerHTML = x; } </script> </body> </html>