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.
html
<!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 >
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.
html
<!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 >
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:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
17 Jun, 2022
Like Article
Save Article