The HTML DOM HR Object represent the <hr> element of an HTML document.
Create hr object−
Syntax
Following is the syntax −
document.createElement(“HR”);
Let us see an example of hr 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; } hr { border-color: #db133a; } </style> <body> <h1>DOM hr Object Demo</h1> <button onclick="createHr()" class="btn">Create a hr object</button> <script> function createHr() { var insElement = document.createElement("HR"); document.body.appendChild(insElement); } </script> </body> </html>
Output
Click on “Create a hr object” button to create a hr object.