6

enter image description here

This is the image of the index on the left on Mozilla Developer Network.

What I would like to ask is this:

What is the difference between Document and document ?

The reason why I am asking is this:

I have always retrieved elements as follows (document with a small d):

document.getElementById("#id");  

and MDN lists it as follows (Document with a capital D) :

Document.getElementById("#id");
An SO User
  • 24,612
  • 35
  • 133
  • 221

1 Answers1

11

document is the actual object for your html page loaded in browser. This is a DOM object.

Document is the function(a DOM interface precisely), which will be used to create the document object. This "Document" is implemented by the browser program. This takes our HTML file as input and creates the "document" object.

Document.getElementById(..) -> wrong. This wont work.
Document.prototype.getElementById(..) This is the right way

Refer this link - Reference link Document Implementation is specific to each browser. But it can be extended. Check this article too. http://perfectionkills.com/whats-wrong-with-extending-the-dom/

The document object could be from separate implementations by browsers based on the file type. For HTML the prototype would be "HTMLDocumentPrototype" (uses Document interface), and for XML it would be just a "Object" and no prototype attached. This might differ from browser to browser, since implementation is specific.

vivek_nk
  • 1,590
  • 16
  • 27
  • What do you mean by `Document is the function` ? :) – An SO User Apr 14 '14 at 04:52
  • function object :) I do not want to say "class" and confuse him, presuming he is aware that object are created by function objects in JS. – vivek_nk Apr 14 '14 at 04:53
  • "He" meaning me. I am the OP. xD No, I am not aware of how that works. Maybe link me to a good resource ? :) – An SO User Apr 14 '14 at 04:54
  • I believe @vivek_nk meant `Document` is the constructor/DOM interface. Constructors are usually of type `function` (and every function can be used as a constructor), though some host objects are constructors that do not implement a `[[Call]]` internal method (hence are not callable functions). – Fabrício Matté Apr 14 '14 at 04:57