The <title> tag defines the title of the document. The title must be text-only, and it is shown in the browser's title bar or in the page's tab. The <title> tag is required in HTML documents!
If you have trouble finding the “<title>” in the sea of HTML, then use the Find function. Again, on Windows, you can select Ctrl + F and then type “title” to quickly find the Title. That's all there is to it. Now you can easily find the webpage Title for any page on your website.
Use the querySelector() Method to Change the Page Title in JavaScript. We can use the document. querySelector() method to pick elements in a document. The title element can be chosen by giving the title element a selector parameter and retrieving the page's main title element.
The title property sets or returns the value of the title attribute of an element, nothing but providing extra information regarding the element. This is mostly used as a tooltip, which displays the text on mouse hovering. Javascript has provided document. title() to get the title.
Use document.title
:
console.log(document.title)
<title>Title test</title>
MDN Web Docs
Put in the URL bar and then click enter:
javascript:alert(document.title);
You can select and copy the text from the alert depending on the website and the web browser you are using.
Can use getElementsByTagName
var x = document.getElementsByTagName("title")[0];
alert(x.innerHTML)
// or
alert(x.textContent)
// or
document.querySelector('title')
Edits as suggested by Paul
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With