Document Nodes

Document Nodes

The HTMLDocument constructor (which inherits from document) creates a DOCUMENT_NODE (i.e., a window.document) in the DOM.

HTMLDocument Properties and Methods

//document own properties
//document own properties and inherited properties
var documentPropertiesIncludeInherited = [];  
for(var p in document){  

//documment inherited properties only
var documentPropertiesOnlyInherited = [];  
for(var p in document){  

Many properties are available, even if the inherited properties were not considered.

  • doctype
  • documentElement
  • implementation.*
  • activeElement
  • body
  • head
  • title
  • lastModified
  • referrer
  • URL
  • defaultview
  • compatMode
  • hasFocus()

The document object provides access to some general information about the HTML document/DOM being loaded.

var d = document;  
console.log('title = ' +d.title);  
console.log('url = ' +d.URL);  
console.log('referrer = ' +d.referrer);  
console.log('lastModified = ' +d.lastModified);  

document nodes can contain one DocumentType node object and one Element node object.

HTML documents typically contain only one doctype (e.g., <!DOCTYPE html>) and one element (e.g., <html lang="en">).

document Provides Shortcuts

Qdocument.doctype refers to <!DOCTYPE>.

document.documentElement refers to <html lang="en">.

document.head refers to <head>

document.body refers to <body>.

Getting a Reference to the Focus/Active Node in the Document

Using the document.activeElement, we can quickly get a reference to the node in the document that is focused/active.


 //get reference to element that is focused/active in the document
console.log(document.activeElement); //logs <textarea>