JavaScript document.title Property
You are Here:
JavaScript document.title Property
The document.title
property gets or sets the current title of the document.
Note: This property applies to HTML, SVG, XUL, and other documents in Gecko.
Get Title
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<head>
<title>Example Page</title>
</head>
<body>
<p>Click on the button to display the title of this page</p>
<button onclick="myFunction()">Click Me</button>
<p id="point"></p>
<script>
var x = document.getElementById("point");
function myFunction(){
x.innerHTML = document.title;
}
</script>
</body>
</html>
Syntax
document.title
Return Values
Value | Explanation |
---|---|
String | Returns the title of the current document. |
Set Title
In the following example, we will set a custom title for the page using JavaScript.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<head>
<title>Example Page</title>
</head>
<body>
<p>Type any title and click 'submit' button</p>
<input type="text" id="myTitle">
<button onclick="myFunction()">submit</button>
<script>
var x = document.getElementById("myTitle");
function myFunction(){
document.title = x.value;
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.