How to get the title of HTML page with JavaScript?

Viewed 258064

How can I get the title of an HTML page with JavaScript?

4 Answers

Use document.title:

console.log(document.title)
<title>Title test</title>

MDN Web Docs

this makes the h1 element the page title. this shows how capable can be javascript for small and big projects.

document.getElementById("text").innerText = document.title;
<title>hello world</title>
<h1 id="text"></h1>

Related