M. Ahmad Zafar
M. Ahmad Zafar

Reputation: 4939

Difference between window.title and document.title

I am have been reading material on JavaScript and there are two ways of accessing the title of the page:

  1. The window.title property
  2. The document.title property

But when applying, the second only works. I am unable to understand why there are two titles and why both of them don't work.

Upvotes: 6

Views: 3744

Answers (1)

dennythecoder
dennythecoder

Reputation: 772

window.document.title is correct.

window.title is incorrect, because the window object doesn't have a title property (all the properties of window are down the left side, you'll see title isn't there).

Upvotes: 10

Related Questions