Javascript DOM HTML Document body Property get body html

Introduction

Get the HTML content of the current document:

var x = document.body.innerHTML;

Click the button to display the HTML content of the document.

View in separate window

<!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>



PreviousNext

Related