Skip to content Skip to sidebar Skip to footer

Get Raw Title As Defined In The HTML Markup With JavaScript

If I have a title with multiple consecutive spaces, document.title returns a string with a single space for each such space combo. Example: [ ] - HTML '

Solution 1:

Looks like I found the answer myself, using the following works:
document.getElementsByTagName('title')[0].textContent

According to the comment of Scott Marcus (this answer), it's better to use:
document.querySelector("title").textContent


Post a Comment for "Get Raw Title As Defined In The HTML Markup With JavaScript"