The HTML DOM Variable Object represent the <var> element of an HTML document.
Create var object−
Syntax
Following is the syntax −
document.createElement(“VAR”);
Let us see an example of var object−
Example
<!DOCTYPE html> <html> <style> body { text-align: center; background-color: #fff; color: #0197F6; } h1 { color: #23CE6B; } .btn { background-color: #fff; border: 2px solid #0197F6; height: 2rem; width: 40%; margin: 2rem auto; display: block; color: #0197F6; outline: none; cursor: pointer; border-radius: 20px; } </style> <body> <h1>DOM var Object Demo</h1> <button onclick="createHr()" class="btn">Create a var object</button> <script> function createHr() { var varElement = document.createElement("VAR"); varElement.innerHTML = 'This is a var element in HTML'; document.body.appendChild(varElement); } </script> </body> </html>
Output
Click on “Create a var object” button to create a var object.