HTML | DOM Title text Property

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.

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

chevron_right


Output:
Before Clicking On Button:

After Clicking On button:

Example-2: This Example sets the text Property.

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

chevron_right


Output :
Before Clicking On button:

After Clicking On button:



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 : Akanksha_Rai



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.