Reputation: 6851
If I have a title with multiple consecutive spaces, document.title
returns a string with a single space for each such space combo.
Example:
<title>[ ]</title>
- HTML
"[ ]"
- document.title
See also image below.
Question - how to get the raw string as it's defined in the HTML document? This caused a bug in one of my scraping scripts where a title should match some other element.
Upvotes: 0
Views: 937
Reputation: 6851
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
Upvotes: 1