Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Title text Property

  • Difficulty Level : Basic
  • Last Updated : 16 Oct, 2020

The DOM Title text Property is used to set or return the text of the title of the document.

Syntax:

  • It returns the text property.
    titleObject.text
  • It is used to set the text property.
    titleObject.text = text

Property Values: It contains the value i.e text which is used to specify the text of the document’s title.

Return Value: It returns a string value which represents the text of the document’s title.

Example-1: This Example returns a text Property.






<!DOCTYPE html>
<html>
  
<head>
    <title>
        DOM Title text Property
    </title>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;"
            GeeksforGeeks 
        </h1>
  
    <h2>
      DOM Title text Property
  </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 Clicking On Button:

After Clicking On button:

Example-2: This Example sets the text Property.




<!DOCTYPE html>
<html>
  
<head>
    <title>
         DOM Title text Property
    </title>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;"
            GeeksforGeeks 
        </h1>
  
    <h2>
      DOM Title text Property
  </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 = "GeeksForGeeks";
            
            document.getElementById("sudo").innerHTML =
              "The title was changed to " + g;
        }
    </script>
</body>
  
</html>

Output :
Before Clicking On button:

After Clicking On button:

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :