Title text Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Title

Description

The text property sets or gets the text of the document's title.

Set the text property with the following Values

Value Description
text Sets the text of the document's title

Return Value

A String, representing the text of the document's title

The following code shows how to return the text of the document's title:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Objects</title>
</head>/* w  ww. j av  a2s.  co  m*/
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var v = document.getElementsByTagName("TITLE")[0].text =;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials