Document title Property - Javascript DOM

Javascript examples for DOM:Document title

Description

The title property sets or gets the title of the current document, which is the text inside the HTML title element.

Set the title property with the following Values

ValueDescription
newTitle Sets a new title text

Return Value

A String, representing the title of the document

The following code shows how to get the title of the current document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<title>My title</title>
</head>/*from  w  w w .j ava 2s.c  om*/
<body>

<button onclick="myFunction()">change the title of the document</button>

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

<script>
function myFunction() {
    var v = document.title;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials