HTML| DOM HR Object

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” represent the element id.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>HTML hr tag</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. 
            var x = document.getElementById("GFG");
            x.style.display = "none";
        }
    </script>
</body>
  
</html>

chevron_right


Output:

Before Clicking On Button :

After Clicking on Button:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Before Clicking On Button:

After Clicking On Button:

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

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : shubham_singh



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.