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.
<!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> |
Output:
Before Clicking On Button:

After Clicking On button:

Example-2: This Example sets the text Property.
<!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> |
Output :
Before Clicking On button:

After Clicking On button:

Recommended Posts:
- HTML | DOM title Property
- HTML | DOM Anchor Text Property
- HTML | DOM Script text Property
- HTML | DOM Input Text value Property
- HTML | DOM Input Text name Property
- HTML | DOM Option text Property
- HTML | DOM Input Text defaultValue Property
- HTML | DOM Input Text readOnly Property
- HTML | DOM Input Text autocomplete Property
- HTML | DOM Input Text autofocus Property
- HTML | DOM Input Text pattern Property
- HTML | DOM Input Text maxLength Property
- HTML | DOM Input Text form Property
- HTML | DOM Input Text required Property
- HTML | DOM Input Text disabled Property
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



