Skip to content
Related Articles

Related Articles

HTML | DOM Title Object
  • Last Updated : 25 Jan, 2019

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:




<!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>                                

Output:
Before Click on the Button :

After Click on the Button:



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




<!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>                                             

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

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :