Javascript DOM HTML HTML Object get

Introduction

The HTML object represents an HTML <html> element.

We can access the <html> element by using document.getElementsByTagName():

var x = document.getElementsByTagName("HTML")[0];

Click the button to get the HTML content of the html element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from w  ww  .  j  ava 2 s  . c o  m*/
  var x = document.getElementsByTagName("HTML")[0].innerHTML;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related