5

In javascript when I access window via Chrome console and then go to the document property I get an object with many kinds of properties: Document DOM

But when I access the document like this window.documentin the console I get a different object it seems:

enter image description here

The latter one looks like the DOM API which we can use to manipulate HTML.

Question:

Why are we getting different objects of document when we access the document object in the above mentioned different ways?

Willem van der Veen
  • 33,665
  • 16
  • 190
  • 155
  • which browser? can you see the document prototype in the second example? – Jaromanda X Nov 19 '17 at 23:46
  • 1
    Good question but also note that there are variations depending on browser used also – charlietfl Nov 19 '17 at 23:46
  • The console has a mind of its own, and it shows you stuff the way it thinks you want to see it. There's no "standard" for what it does. It's possible that `window["document"]` does something different than `window.document` for example. – Pointy Nov 19 '17 at 23:46
  • 1
    Each browser interprets and displays differently, look in Firefox and compare it to Chrome – zer00ne Nov 19 '17 at 23:46
  • Using Chrome browser – Willem van der Veen Nov 19 '17 at 23:47
  • Don't expect an absolute answer. Keep in mind that the dom is not a javascript object – charlietfl Nov 19 '17 at 23:51
  • You can't find the DOM at the window.document? – Willem van der Veen Nov 19 '17 at 23:51
  • 1
    You can access the dom using javascript but it is it's own beast – charlietfl Nov 19 '17 at 23:52
  • Ow thanks a lot, I thought it was a javascript object – Willem van der Veen Nov 19 '17 at 23:53
  • That's just the way chrome's console decided to render all `Document` objects. You can check this with `console.log(document.implementation.createDocument('http://www.w3.org/1999/xhtml', null))`. But Yes, for the js engine, `window.document` **is a js object.** Not sure what @charlietfl tried to say here. Also, indeed, if you want to be sure it won't use fancy representations, use `console.dir`. – Kaiido Nov 20 '17 at 05:22

0 Answers0