Categories
JavaScript Answers

How to get current HTML page title with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *