class js.html.Document extends Node

Available on js

Each web page loaded in the browser has its own document object. This object serves as an entry point to the web page's content (the DOM tree, including elements such as <body> and <table> ) and provides functionality global to the document (such as obtaining the page's URL and creating new elements in the document).

A document object can be obtained from various APIs:

Depending on the kind of the document (e.g. HTML or XML) different APIs may be available on the document object. This theoretical availability of APIs is usually described in terms of implementing interfaces defined in the relevant W3C DOM specifications:

  • All document objects implement the DOM Core Document and Node interfaces, meaning that the "core" properties and methods are available for all kinds of documents.
  • In addition to the generalized DOM Core document interface, HTML documents also implement the HTMLDocument interface, which is a more specialized interface for dealing with HTML documents (e.g., document.cookie, document.alinkColor).
  • XUL documents (available to Mozilla add-on and application developers) implement their own additions to the core Document functionality.

Methods or properties listed here that are part of a more specialized interface have an asterisk (*) next to them and have additional information in the  Availability column.

Note that some APIs listed below are not available in all browsers for various reasons:

  • Obsolete: on its way of being removed from supporting browsers.
  • Non-standard: either an experimental feature not (yet?) agreed upon by all vendors, or a feature targeted specifically at the code running in a specific browser (e.g. Mozilla has a few DOM APIs created for its add-ons and application development).
  • Part of a completed or an emerging standard, but not (yet?) implemented in all browsers or implemented in the newest versions of the browsers.

Detailed browser compatibility tables are located at the pages describing each property or method.



Documentation for this class was provided by MDN.

Instance Fields

var URL:String

Returns a string containing the URL of the current document.

var activeElement:Element

Returns the currently focused element

var alinkColor:String

Returns or sets the color of active links in the document body.

var anchors:HTMLCollection

Returns a list of all of the anchors in the document.

var applets:HTMLCollection

Returns an ordered list of the applets within a document.

var bgColor:String

Gets/sets the background color of the current document.

var body:Element

Returns the BODY node of the current document. Setter throws DOMException.

var characterSet:String

Returns the character set being used by the document.

var compatMode:String

Indicates whether the document is rendered in Quirks or Strict mode.

var cookie:String

Returns a semicolon-separated list of the cookies for that document or sets a single cookie. Getter throws DOMException. Setter throws DOMException.

var defaultView:DOMWindow

Returns a reference to the window object.

var designMode:String

Gets/sets WYSYWIG editing capability of Midas. It can only be used for HTML documents.

var dir:String

Gets/sets directionality (rtl/ltr) of the document

var doctype:DocumentType

Returns the Document Type Definition (DTD) of the current document.

var documentElement:Element

Returns the Element that is a direct child of document. For HTML documents, this is normally the HTML element.

var documentURI:String

Returns the document location.

var domain:String

Returns the domain of the current document. Setter throws DOMException.

var embeds:HTMLCollection

Returns a list of the embedded OBJECTS within the current document.

var fgColor:String

Gets/sets the foreground color, or text color, of the current document.

var forms:HTMLCollection

Returns a list of the FORM elements within the current document.

var head:HeadElement

Returns the HEAD node of the current document.

var height:Int

Gets/sets the height of the current document.

var images:HTMLCollection

Returns a list of the images in the current document.

var implementation:DOMImplementation

Returns the DOM implementation associated with the current document.

var inputEncoding:String

Returns the encoding used when the document was parsed.

var lastModified:String

Returns the date on which the document was last modified.

var linkColor:String

Gets/sets the color of hyperlinks in the document.

var links:HTMLCollection

Returns a list of all the hyperlinks in the document.

var location:Location

Returns the URI of the current document.

var onreadystatechange:EventListener

Returns the event handling code for the readystatechange event.

Gecko 9.0 note
(Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6)

Starting in Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6) , you can now use the syntax if ("onabort" in document) to determine whether or not a given event handler property exists. This is because event handler interfaces have been updated to be proper web IDL interfaces. See DOM event handlers for details.

var plugins:HTMLCollection

Returns a list of the available plugins.

var readyState:String

Returns loading status of the document

var referrer:String

Returns the URI of the page that linked to this page.

var scripts:HTMLCollection

Returns all the <script> elements on the document.

var styleSheets:StyleSheetList

Returns a list of the stylesheet objects on the current document.

var title:String

Returns the title of the current document.

var vlinkColor:String

Gets/sets the color of visited hyperlinks.

var width:Int

Returns the width of the current document.

var xmlEncoding:String

Returns the encoding as determined by the XML declaration.

Firefox 10 and later don't implement it anymore.

var xmlStandalone:Bool

Returns true if the XML declaration specifies the document is standalone (e.g., An external part of the DTD affects the document's content), else false. Setter throws DOMException.

var xmlVersion:String

Returns the version number as specified in the XML declaration or "1.0" if the declaration is absent. Setter throws DOMException.

function adoptNode(source:Node):Node

function captureEvents():Void

function clear():Void

function close():Void

function createAnchorElement():AnchorElement

A typed shortcut for createElement("a").

function createAppletElement():AppletElement

A typed shortcut for createElement("applet").

function createAreaElement():AreaElement

A typed shortcut for createElement("area").

function createAttribute(name:String):Attr

function createAttributeNS(?namespaceURI:String, ?qualifiedName:String):Attr

function createAudioElement():AudioElement

A typed shortcut for createElement("audio").

function createBRElement():BRElement

A typed shortcut for createElement("br").

function createBaseElement():BaseElement

A typed shortcut for createElement("base").

function createBaseFontElement():BaseFontElement

A typed shortcut for createElement("basefont").

function createBodyElement():BodyElement

A typed shortcut for createElement("body").

function createButtonElement():ButtonElement

A typed shortcut for createElement("button").

function createCanvasElement():CanvasElement

A typed shortcut for createElement("canvas").

function createContentElement():ContentElement

A typed shortcut for createElement("content").

function createDListElement():DListElement

A typed shortcut for createElement("dl").

function createDataListElement():DataListElement

A typed shortcut for createElement("datalist").

function createDetailsElement():DetailsElement

A typed shortcut for createElement("details").

function createDirectoryElement():DirectoryElement

A typed shortcut for createElement("dir").

function createDivElement():DivElement

A typed shortcut for createElement("div").

function createElement(?tagName:String):Element

function createElementNS(?namespaceURI:String, ?qualifiedName:String):Element

function createEmbedElement():EmbedElement

A typed shortcut for createElement("embed").

function createEvent(eventType:String):Event

function createFieldSetElement():FieldSetElement

A typed shortcut for createElement("fieldset").

function createFontElement():FontElement

A typed shortcut for createElement("font").

function createFormElement():FormElement

A typed shortcut for createElement("form").

function createFrameElement():FrameElement

A typed shortcut for createElement("frame").

function createFrameSetElement():FrameSetElement

A typed shortcut for createElement("frameset").

function createHRElement():HRElement

A typed shortcut for createElement("hr").

function createHeadElement():HeadElement

A typed shortcut for createElement("head").

function createHtmlElement():HtmlElement

A typed shortcut for createElement("html").

function createIFrameElement():IFrameElement

A typed shortcut for createElement("iframe").

function createImageElement():ImageElement

A typed shortcut for createElement("img").

function createInputElement():InputElement

A typed shortcut for createElement("input").

function createKeygenElement():KeygenElement

A typed shortcut for createElement("keygen").

function createLIElement():LIElement

A typed shortcut for createElement("li").

function createLabelElement():LabelElement

A typed shortcut for createElement("label").

function createLegendElement():LegendElement

A typed shortcut for createElement("legend").

function createLinkElement():LinkElement

A typed shortcut for createElement("link").

function createMapElement():MapElement

A typed shortcut for createElement("map").

function createMarqueeElement():MarqueeElement

A typed shortcut for createElement("marquee").

function createMediaElement():MediaElement

A typed shortcut for createElement("media").

function createMenuElement():MenuElement

A typed shortcut for createElement("menu").

function createMetaElement():MetaElement

A typed shortcut for createElement("meta").

function createMeterElement():MeterElement

A typed shortcut for createElement("meter").

function createModElement():ModElement

A typed shortcut for createElement("mod").

function createNSResolver(nodeResolver:Node):XPathNSResolver

function createNodeIterator(root:Node, whatToShow:Int, filter:NodeFilter, expandEntityReferences:Bool):NodeIterator

function createOListElement():OListElement

A typed shortcut for createElement("ol").

function createObjectElement():ObjectElement

A typed shortcut for createElement("object").

function createOptGroupElement():OptGroupElement

A typed shortcut for createElement("optgroup").

function createOptionElement():OptionElement

A typed shortcut for createElement("option").

function createOutputElement():OutputElement

A typed shortcut for createElement("output").

function createParagraphElement():ParagraphElement

A typed shortcut for createElement("p").

function createParamElement():ParamElement

A typed shortcut for createElement("param").

function createPreElement():PreElement

A typed shortcut for createElement("pre").

function createProgressElement():ProgressElement

A typed shortcut for createElement("progress").

function createQuoteElement():QuoteElement

A typed shortcut for createElement("quote").

function createRange():Range

function createScriptElement():ScriptElement

A typed shortcut for createElement("script").

function createSelectElement():SelectElement

A typed shortcut for createElement("select").

function createShadowElement():ShadowElement

A typed shortcut for createElement("shadow").

function createSourceElement():SourceElement

A typed shortcut for createElement("source").

function createSpanElement():SpanElement

A typed shortcut for createElement("span").

function createStyleElement():StyleElement

A typed shortcut for createElement("style").

function createTableCaptionElement():TableCaptionElement

A typed shortcut for createElement("caption").

function createTableCellElement():TableCellElement

A typed shortcut for createElement("td").

function createTableColElement():TableColElement

A typed shortcut for createElement("col").

function createTableElement():TableElement

A typed shortcut for createElement("table").

function createTableRowElement():TableRowElement

A typed shortcut for createElement("tr").

function createTableSectionElement():TableSectionElement

A typed shortcut for createElement("thead").

function createTextAreaElement():TextAreaElement

A typed shortcut for createElement("textarea").

function createTextNode(data:String):Text

function createTitleElement():TitleElement

A typed shortcut for createElement("title").

function createTouch(window:DOMWindow, target:EventTarget, identifier:Int, pageX:Int, pageY:Int, screenX:Int, screenY:Int, radiusX:Int, radiusY:Int, rotationAngle:Float, force:Float):Touch

function createTrackElement():TrackElement

A typed shortcut for createElement("track").

function createTreeWalker(root:Node, whatToShow:Int, filter:NodeFilter, expandEntityReferences:Bool):TreeWalker

function createUListElement():UListElement

A typed shortcut for createElement("ul").

function createVideoElement():VideoElement

A typed shortcut for createElement("video").

function evaluate(expression:String, contextNode:Node, resolver:XPathNSResolver, type:Int, inResult:XPathResult):XPathResult

function execCommand(command:String, userInterface:Bool, ?value:String):Bool

function exitFullscreen():Void

function getCSSCanvasContext(contextId:String, name:String, width:Int, height:Int):CanvasRenderingContext

function getElementById(elementId:String):Element

function getElementsByName(elementName:String):NodeList

function getElementsByTagNameNS(?namespaceURI:String, localName:String):NodeList

function getOverrideStyle(element:Element, pseudoElement:String):CSSStyleDeclaration

function hasFocus():Bool

function importNode(importedNode:Node, ?deep:Bool):Node

function open():Void

function queryCommandEnabled(command:String):Bool

function queryCommandIndeterm(command:String):Bool

function queryCommandState(command:String):Bool

function queryCommandValue(command:String):String

function querySelector(selectors:String):Element

function querySelectorAll(selectors:String):NodeList

function releaseEvents():Void

function write(text:String):Void

function writeln(text:String):Void