How to get current HTML page title with JavaScript?

Sometimes, we want to get current HTML page title with JavaScript.

In this article, we’ll look at how to get current HTML page title with JavaScript.

How to get current HTML page title with JavaScript?

To get current HTML page title with JavaScript, we use the get the inner text of the title element.

For instance, we write

const [titleElement] = document.getElementsByTagName("title");
const title = titleElement.innerText;

to get the title element with getElementsByTagName and destructuring.

Then we get the title element’s inner text value with innerText.

Conclusion

To get current HTML page title with JavaScript, we use the get the inner text of the title element.