A Platform To Learn To Code

JAVASCRIPT DOM Document



What is Document in Javascript?

The Document is an interface that represents the web pages. It serves as an entry point into the content of web pages i.e DOM Tree.

The document includes everything about the webpage both which is visible and which is not visible on screen.

A large amount of information about the webpage is also available with the document, which can be accessed by properties and methods provided by the document.

HTML document implements HTMLDocument interface while XML and SVG documents implements XMLDocument interface.

Example: document

Run the code

Document Constructor

Javascript provides a Constructor for creating documents. The Document is used to create a new document. Example: new Document()

Example: new Document()

Run the code

Javascript Document Methods

The document object has a bunch of methods which we use to grab the elements, write something in document, create new element in document, delete older element and much more.

Methods or Property Description
Document.activeElement It returns element cursor is focusing to in document
Document.addEventListener It attaches event handler to the element
Document.all It return collection of all elements present in the document
Document.anchors Returns all anchor tag present in the document which has name attribute
Document.baseURI It returns base URI of the document
Document.body It return body of document as an object
Document.characterSet It returns character encoding for the document
Document.doctype Returns the Document type Definition of the document
Document.documentElement Returns the element that is direct child to the document
Document.documentURI Returns document URI as a string
Document.forms Returns a collection of all forms present in the document
Document.head It return head of document as an object
Document.scripts Returns all script element on the document
Document.title It return title of document as an object

Document.activeElement

Example

Run the code

Document.addEventListener

Example

Run the code

Document.all

Example

Run the code

Document.anchors

Example

Run the code

Document.baseURI

Example

Run the code

Document.characterSet

Example

Run the code

Document.doctype

Example

Run the code

Document.title

Example

Run the code

In Next chapter we will see more different methods for different purposes.

Javascript DOM Methods