HTML DOM HTML Object

HTMLWeb DevelopmentFront End Technology

The HTML Object represents the element of an HTML document.

Let us see how to access HTML object −

Syntax

Following is the syntax −

document.getElementsByTagName(“HTML”)

Let us see an example of HTML object −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   body{
      text-align:center;
   }
   .btn{
      background-color:lightblue;
      border:none;
      height:2rem;
      border-radius:50px;
      width:60%;
   margin:1rem auto;
   }
   .show{
      font-size:1rem;
      font-weight:bold;
      color:orange;
      border:2px solid green;
      padding:10px;
      display:none;
   }
</style>
</head>
<body>
<h1>DOM HTML Object Example</h1>
<button type="button" onclick="getContent()" class="btn">Click me to get content
inside HTML tag</button>
<div class="show"></div>
<script>
   function getContent(){
      var content=document.getElementsByTagName("HTML")[0].innerHTML;
      document.querySelector(".show").innerHTML = content;
      document.querySelector(".show").style.display ="block";
   }
</script>
</body>
</html>

Output

This will produce the following output −

Click on “blue” button to get all content inside this page tag −

raja
Published on 16-Jul-2019 17:18:08
Advertisements