Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Document and document? [duplicate]

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");
like image 356
An SO User Avatar asked Apr 14 '14 04:04

An SO User


1 Answers

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.

like image 107
vivek_nk Avatar answered Oct 16 '22 03:10

vivek_nk