The text
property sets or gets the text of the document's title.
text |
Yes | Yes | Yes | Yes | Yes |
Return the text property.
var v = titleObject.text
Set the text property.
titleObject.text=text
Value | Description |
---|---|
text | Set the title text |
A String type value representing the text of the document's title.
The following code shows how to get the document's title.
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Objects</title>
</head><!-- ww w . j a v a 2 s . co m-->
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementsByTagName("TITLE")[0].text;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the document's title.
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Objects</title>
</head><!--from w ww . jav a 2s . co m-->
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementsByTagName("TITLE")[0].text = "A new title text..";
document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows: