HTML | DOM Heading Object

The DOM Heading Object is used to represent the HTML <Heading> elements. The Heading elements is accessed by getElementById().

Properties:

  • align: This element contains a align attribute which is used to sets or returns the alignment of the heading elements.

Syntax:

document.getElementById("ID");

Where “id” is the ID assigned to the “headings” tag.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
    <center>
        
        <!-- assigning id to h1. -->
        <h1 id="GFG" style="color:green;">
          GeeksForGeeks
        </h1>
        <h2> DOM Headings Object </h2>
        
        <button onclick="myGeeks()">
          Submit
        </button>
        
        <script>
            function myGeeks() {
                  
                //  Accessing heading.
                var g = document.getElementById("GFG");
                g.style.color = "red";
                g.style.fontSize = "35px";
            }
        </script>
    </center>
</body>
  
</html>

chevron_right


Output:
Before Clicking On Button:

After Clicking On Button:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
    <h1 id="GFG" style="color:green;">
      GeeksForGeeks
    </h1>
    <h2> DOM Headings Object </h2>
    <button onclick="myGeeks()">Submit</button>
    <script>
        function myGeeks() {
            
            //  Creating "H1" heading.
            var g = document.createElement("H1");
            var f = document.createTextNode(
              "Welcome to GeeksForGeeks");
            g.appendChild(f);
            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 Headings 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.




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.