HTML | DOM Title Object

The Title Object in HTML DOM is used to represent the HTML <title> element. The <title> element can be accessed by using getElementByTagName() method.

Syntax:

document.getElementByTagName();

Properties: The title object contains single property text which is used to set or return a text or content of title to the document.



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <title>
            DOM Title Object
        </title
    </head
      
    <body style = "text-align:center;"
      
        <h1 style = "color:green;">
            GeeksforGeeks
        </h1
          
        <h2>DOM Title Object</h2
          
        <p>Welcome to GeeksforGeeks!</p>
          
        <button onclick = "myGeeks()">
            Submit
        </button>
  
        <p id = "sudo"></p>
          
        <!-- script to display tag name -->
        <script>
            function myGeeks() {
                var g = document.getElementsByTagName("TITLE")[0].text;
                document.getElementById("sudo").innerHTML = g;
            
        </script>
    </body
</html>                                

chevron_right


Output:
Before Click on the Button :

After Click on the Button:

Example 2: Title Object can be created by using the document.createElement method.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head
</head
      
<body style = "text-align:center;"
  
    <h1 style = "color:green;">
        GeeksforGeeks
    </h1
      
    <h2>DOM Title Object</h2
      
    <p>Welcome to GeeksforGeeks!</p
      
    <button onclick ="myGeeks()">
        Submit
    </button>
  
    <p id = "sudo"></p>
  
    <script>
        function myGeeks() {
            var tit_ele = document.createElement("TITLE");
            var obj = document.createTextNode("HTML DOM Objects");
            tit_ele.appendChild(obj);
            document.head.appendChild(tit_ele);
          
            document.getElementById("sudo").innerHTML
                    = "HTML DOM title Object Created"; 
        }
    </script>
</body
  
</html>                                             

chevron_right


Output:
Before Click on the Button:

After Click on the Button:

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

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


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.