Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
<!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 −

Advertisements