Open In App

HTML DOM HR Object

Improve
Improve
Like Article
Like
Save
Share
Report

The DOM HR Object is used to represent the HTML <hr> element. The hr element is accessed by getElementById()

Properties:

  • Align: It is used to set or return the alignment of a horizontal element.
  • color: It is used to set or return the color of the horizontal element.
  • noshade: It is used to set or return the noshade property in a horizontal element.
  • size: It is used to set or return the height of a horizontal line.
  • width: It is used to set or return the width of a horizontal line.

Syntax:

document.getElementById("ID");

Where “ID” represents the element id. 

Example 1: In this example, we will see the use of DOM HR Object.

html




<!DOCTYPE html>
<html>
<head>
    <title>HTML DOM HR Object</title>
</head>
<body>
    <h1>GeeksForGeeks</h1>
    <h2>DOM HR Object</h2>
    <p>There is a horizontal
        rule below this paragraph.</p>
    <!-- Assigning id to 'hr' tag. -->
    <hr id="GFG">
    <p>This is a horizontal rule above this paragraph.</p>
    <button onclick="myGeeks()">Try it</button>
    <script>
        function myGeeks() {
            // Accessing 'hr' tag.
            let x = document.getElementById("GFG");
            x.style.display = "none";
        }
    </script>
</body>
</html>


Output: 

 

Example 2: HR Object can be created by using the document.createElement Method. 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>HTML DOM HR Object
    </title>
</head>
<body>
    <h1 style="color:green;">GeeksForGeeks</h1>
    <h2>DOM HR Object</h2>
    <button onclick="myGeeks()">Submit</button>
    <script>
        function myGeeks() {
            let g = document.createElement("HR");
            document.body.appendChild(g);
        }
    </script>
</body>
</html>


Output: 

 

Supported Browsers: The browser supported by DOM HR Object are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


Last Updated : 14 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads