HTML DOM Subscript Object


The HTML DOM Subscript Object represent the <sub> element of an HTML document.

Let us see how to create subscript object

Syntax

Following is the syntax −

document.createElement(“SUB”);

Example

Let us see an example of HTML DOM subscript object −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      text-align: center;
      background-color: #fff;
      color: #0197F6;
   }
   h1 {
      color: #23CE6B;
   }
   .btn {
      background-color: #fff;
      border: 1.5px dashed #0197F6;
      height: 2rem;
      border-radius: 2px;
      width: 60%;
      margin: 2rem auto;
      display: block;
      color: #0197F6;
      outline: none;
      cursor: pointer;
   }
</style>
</head>
<body>
<h1>DOM subscript Object Demo</h1>
<button onclick="createSub()" class="btn">Create a subscript object</button>
<script>
   function createSub() {
      var subElement = document.createElement("SUB");
      subElement.innerHTML = "This is a subscript element"
      document.body.appendChild(subElement);
   }
</script>
</body>
</html>

Output

This will produce the following output −

Click on “Create a subscript object” button to create a subscript object. The text visible after button click is a subscript, which appears half a character below the normal line −

Updated on: 30-Jul-2019

58 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements