Change the Title of the Document with JavaScript

02/13/2022
Contents
In this article, I will introduce how to change the title of the document with JavaScript.
The document.title property
In JavaScript, the document.title property is used when you want to change the title of a web page.
Here’s how to get the title of the document.
let docTitle = document.title;
If you want to change the title, do as follows.
document.title = "newTitle";
Sample Code
Below is sample code to change the title of the web page.
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>oldTitle</title>
</head>
<body>
<script>
console.log(document.title); // "oldTitle"
document.title = "newTitle";
console.log(document.title); // "newTitle"
</script>
</body>
</html>