<!DOCTYPE html>
<html>
<head>
<title>
JavaScript | Get the entire document HTML as a string.
</title>
</head>
<body style="text-align:center;" id="body">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<p id="GFG_UP" style="font-size: 15px; font-weight: bold;">
</p>
<button onclick="GFG_Fun(); ">
click here
</button>
<script>
var up = document.getElementById('GFG_UP');
up.innerHTML = 'Click on the button to convert whole document to string';
function GFG_Fun() {
var string = document.documentElement.innerHTML;
alert(string);
}
</script>
</body>
</html>