WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

The HTML DOM Document Object


HTML DOM Nodes

In the HTML DOM (Document Object Model), everything is a node:

  • The report itself is an archive node
  • All HTML components are component nodes
  • All HTML characteristics are property nodes
  • Text inside HTML components are content nodes
  • Comments are remark nodes

The Document Object

When a HTML record is stacked into an internet browser, it turns into a document object.

The record object is the root hub of the HTML archive and the "owner" of all other nodes:
(element hubs, content hubs, property hubs, and remark nodes).

The record object gives properties and techniques to get to all hub objects, from inside JavaScript.

Tip: The archive is a piece of the Window object and can be gotten to as window.document.


Browser Support

Object
Document Yes Yes Yes Yes Yes

The Document Object is bolstered in all major browsers.


Document Object Properties and Methods

The following properties and techniques can be utilized on HTML documents:

Property/Method Description
document.activeElement Returns the presently engaged component in the document
document.addEventListener() Attaches an occasion handler to the document
document.adoptNode() Adopts a hub from another document
document.anchors Returns a gathering of all <a> components in the archive that have a name attribute
document.applets Returns a gathering of all <applet> components in the document
document.baseURI Returns unquestionably the base URI of a document
document.body Sets or returns the record's body (the <body> element)
document.close() Closes the yield stream recently opened with document.open()
document.cookie Returns all name/esteem sets of treats in the document
document.createAttribute() Creates a quality node
document.createComment() Creates a Comment hub with the predetermined text
document.createDocumentFragment() Creates an unfilled DocumentFragment node
document.createElement() Creates an Element node
document.createTextNode() Creates a Text node
document.doctype Returns the Document Type Declaration related with the document
document.documentElement Returns the Document Element of the record (the <html> element)
document.documentMode Returns the mode utilized by the program to render the document
< document.documentURI Sets or returns the area of the document
document.domain Returns the space name of the server that stacked the document
document.domConfig Obsolete. Returns the DOM arrangement of the document
document.embeds Returns a gathering of all <embed> components the document
document.forms Returns a gathering of all <form> components in the document
document.getElementById() Returns the component that has the ID characteristic with the predetermined value
document.getElementsByClassName() Returns a NodeList containing all components with the predefined class name
document.getElementsByName() Returns a NodeList containing all components with a predefined name
document.getElementsByTagName() Returns a NodeList containing all components with the predefined tag name
document.hasFocus() Returns a Boolean esteem demonstrating whether the record has focus
document.head Returns the <head> component of the document
document.images Returns an accumulation of all <img> components in the document
document.implementation Returns the DOMImplementation object that handles this document
document.importNode() Imports a hub from another document
document.inputEncoding Returns the encoding, character set, utilized for the document
document.lastModified Returns the date and time the report was last modified
document.links Returns an accumulation of all <a> and <area> components in the archive that have a href attribute
document.normalize() Removes void Text hubs, and joins neighboring nodes
document.normalizeDocument() Removes void Text hubs, and joins neighboring nodes
document.open() Opens a HTML yield stream to gather yield from document.write()
document.querySelector() Returns the primary component that coordinates a predefined CSS selector(s) in the document
document.querySelectorAll() Returns a static NodeList containing all components that coordinates a indicated CSS selector(s) in the document
document.readyState Returns the (stacking) status of the document
< document.referrer Returns the URL of the report that stacked the current document
document.removeEventListener() Removes an occasion handler from the record (that has been connected with the addEventListener() method)
document.renameNode() Renames the predefined node
document.scripts Returns a gathering of <script> components in the document
document.strictErrorChecking Sets or returns whether blunder checking is upheld or not
document.title Sets or returns the title of the document
document.URL Returns the full URL of the HTML document
document.write() Writes HTML articulations or JavaScript code to a document
document.writeln() Same as compose(), yet includes a newline character after each statement

Warning !!!

In the W3C DOM Core, the Document object acquires all properties and techniques from the Node object.

Many of these properties and strategies have neither rhyme nor reason utilized on documents.

Avoid utilizing these hub object properties and strategies on HTML record objects:

 Property/Method Reason for avoiding
document.attributes Documents don't have attributes
document.hasAttributes() Documents don't have attributes
document.nextSibling Documents don't have siblings
document.nodeName This is dependably #document
document.nodeType This is dependably 9 (DOCUMENT_NODE)
document.nodeValue Documents don't have a hub value
document.ownerDocument Documents don't have a proprietor document
document.ownerElement Documents don't have a proprietor element
document.parentNode Documents don't have a parent node
document.previousSibling Documents don't have siblings
document.textContent Documents don't have a content content