Document

Module: JavaScript DOM API

The document of the view.

#include <Document.idl>

Inherits from Node, EventTarget

Inherited by HTMLDocument

Public Functions

Name
CommentcreateComment(DOMString data)
Creates a new comment node.
NodeIteratorcreateNodeIterator(Node root, optional unsigned long whatToShow =0xFFFFFFFF, optional NodeFilter? filter =null)
AttrcreateAttribute(DOMString localName)
AttrcreateAttributeNS(DOMString? namespace, DOMString qualifiedName)
Create new attribute node with an associated namespace.
NodeimportNode(Node node, optional boolean deep =false)
Creates a new copy of the specified Node or DocumentFragment from another document so that it can be inserted into the current Document.
NodecreateElement(CSSString tagName)
Create a new node.
DocumentFragmentcreateDocumentFragment()
Create new DocumentFragment.
NodecreateElementNS(CSSString? ns, CSSString tagName)
NodecreateTextNode(optional DOMString data)
Creates a new Text node.
EventcreateEvent(CSSString eventType)
Create a new event.
NodeListgetElementsByName(optional DOMString elementName)
Get all nodes with a certain name.
NodeListgetElementsByTagName(DOMString localName)
Get all nodes with a certain tag.
ElementgetElementById(DOMString elementId)
Get a element by its Id.
voidwrite(DOMString markup)
Writes a string of text to a document stream opened by document.open()
booleanhasFocus()
Indicating whether the document or any element inside the document has focus.
NodeListgetElementsByClassName(DOMString classNames)
Get all nodes with a certain class.
ElementelementFromPoint(float x, float y, optional DOMString compositionId)
Returns topmost element at the position.
sequence< Element >elementsFromPoint(float x, float y)
Returns array of elements at the position.
ElementquerySelector(DOMString selectors)
NodeListquerySelectorAll(DOMString selectors)
SelectiongetSelection()
Returns a Selection object representing the range of text selected by the user, or the current position of the caret.
CaretPositioncaretPositionFromPoint(float x, float y)
Returns a CaretPosition object containing the DOM node containing the caret, and caret’s character offset within that node.

Public Attributes

Name
readonly attribute USVStringURL
Returns the document location as a string.
readonly attribute USVStringdocumentURI
Returns the document location as a string.
readonly attribute USVStringorigin
Returns the document’s origin.
readonly attribute DOMStringcompatMode
Indicates whether the document is rendered in Quirks mode or Standards mode.
readonly attribute DOMStringcharacterSet
Returns the character encoding of the current document. The character encoding is the character set used for rendering the document, which may be different from the encoding specified by the page.
readonly attribute DOMStringcharset
historical alias of .characterSet
readonly attribute DOMStringinputEncoding
historical alias of .characterSet
readonly attribute DOMStringcontentType
Returns the MIME type that the document is being rendered as.
readonly attribute DocumentTypedoctype
Returns the Document Type Declaration (DTD) associated with current document.
readonly attribute Elementbody
The document body.
readonly attribute ElementdocumentElement
The root element of the document.
readonly attribute WindowdefaultView
The window object associated with the document.
readonly attribute Elementhead
The document head element.
readonly attribute DOMStringreadyState
Describes the loading state of the document (loading/interactive/complete)
readonly attribute ElementactiveElement
The deepest element in the document through which or to which key events are being routed. This is, roughly speaking, the focused element in the document.
readonly attribute HTMLScriptElementcurrentScript
readonly attribute StyleSheetListstyleSheets
attribute EventSetterabort
attribute EventSetterblur
attribute EventSetterclick
attribute EventSetterauxclick
attribute EventSetterdblclick
attribute EventSettererror
attribute EventSetterfocus
attribute EventSetterkeydown
attribute EventSetterkeypress
attribute EventSetterkeyup
attribute EventSetterload
attribute EventSettermousedown
attribute EventSettermouseover
attribute EventSettermouseout
attribute EventSettermouseenter
attribute EventSettermouseleave
attribute EventSettermousemove
attribute EventSettermouseup
attribute EventSetterinput
attribute EventSetterscroll
attribute EventSetterwheel
attribute EventSettertouchstart
attribute EventSettertouchend
attribute EventSettertouchmove

Additional inherited members

Public Functions inherited from Node

Name
NoderemoveChild(Node oldChild)
remove a child node
NodeappendChild(Node newChild)
append a node as a child
voidappend((Node or DOMString)… newChildren)
append nodes and string objects as children, where the string objects are inserted as equivalent Text nodes
NodereplaceChild(Node newChild, Node oldChild)
replace oldChild with newChild
NodeinsertBefore(Node node, Node? referenceNode)
insert a node before the reference node, as a child of the current node
NodecloneNode(optional boolean deep =false)
booleanisEqualNode(Node? otherNode)
booleanisSameNode(Node? otherNode)
booleanhasChildNodes()
booleancontains(Node? other)
DOMStringlookupPrefix(DOMString? namespace)
booleanisDefaultNamespace(DOMString? namespace)
voidnormalize()
unsigned shortcompareDocumentPosition(Node other)
NodegetRootNode(optional GetRootNodeOptions options)
DOMStringlookupNamespaceURI(DOMString? prefix)

Public Attributes inherited from Node

Name
const unsigned shortELEMENT_NODE
const unsigned shortATTRIBUTE_NODE
const unsigned shortTEXT_NODE
const unsigned shortCDATA_SECTION_NODE
const unsigned shortENTITY_REFERENCE_NODE
const unsigned shortENTITY_NODE
const unsigned shortPROCESSING_INSTRUCTION_NODE
const unsigned shortCOMMENT_NODE
const unsigned shortDOCUMENT_NODE
const unsigned shortDOCUMENT_TYPE_NODE
const unsigned shortDOCUMENT_FRAGMENT_NODE
const unsigned shortNOTATION_NODE
const unsigned shortDOCUMENT_POSITION_DISCONNECTED
const unsigned shortDOCUMENT_POSITION_PRECEDING
const unsigned shortDOCUMENT_POSITION_FOLLOWING
const unsigned shortDOCUMENT_POSITION_CONTAINS
const unsigned shortDOCUMENT_POSITION_CONTAINED_BY
const unsigned shortDOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
readonly attribute DOMStringnodeName
attribute DOMStringnodeValue
attribute DOMStringtextContent
readonly attribute unsigned shortnodeType
type of the node
readonly attribute NodeparentNode
parent of the node
readonly attribute ElementparentElement
parent element of the node. If parent is not an Element, returns null.
readonly attribute NodeListchildNodes
list of the children of this node
readonly attribute NodefirstChild
the node’s first child in the tree, or null if the node is childless
readonly attribute NodelastChild
last child of the node, or null if there are no child elements
readonly attribute NodepreviousSibling
the node immediately preceding the specified one in its parent’s children, or null if the specified node is the first in that list
readonly attribute NodenextSibling
the node immediately following the specified one in its parent’s children, or null if the specified node is the last node in that list
readonly attribute DocumentownerDocument
The Document object associated with this node. This is also the Document object used to create new nodes. When this node is a Document or a DocumentType which is not used with any Document yet, this is null.
readonly attribute USVStringbaseURI
readonly attribute booleanisConnected
attribute EventSetterslotchange

Public Functions inherited from EventTarget

Name
voidaddEventListener(DOMInternedString type, EventListener listener, optional boolean useCapture)
voidremoveEventListener(DOMInternedString type, EventListener listener, optional boolean useCapture)
booleandispatchEvent(Event event)

Public Functions Documentation

function createComment

Comment createComment(
    DOMString data
)

Creates a new comment node.

Return: the newly created node, not attached

function createNodeIterator

NodeIterator createNodeIterator(
    Node root,
    optional unsigned long whatToShow =0xFFFFFFFF,
    optional NodeFilter? filter =null
)

Return: a new NodeIterator object.

function createAttribute

Attr createAttribute(
    DOMString localName
)

Parameters:

  • localName is a string containing the name of the attribute.

Return: new attribute node

function createAttributeNS

Attr createAttributeNS(
    DOMString? namespace,
    DOMString qualifiedName
)

Create new attribute node with an associated namespace.

Parameters:

  • namespace the URI of the namespace.
  • qualifiedName the tag name and prefix of the attribute

Return: new attribute node

function importNode

Node importNode(
    Node node,
    optional boolean deep =false
)

Creates a new copy of the specified Node or DocumentFragment from another document so that it can be inserted into the current Document.

Return: the newly created node, not attached

function createElement

Node createElement(
    CSSString tagName
)

Create a new node.

Parameters:

  • tagName the type of the new node

Return: the newly created node, not attached

function createDocumentFragment

DocumentFragment createDocumentFragment()

Create new DocumentFragment.

Return: the newly created DocumentFragment

function createElementNS

Node createElementNS(
    CSSString? ns,
    CSSString tagName
)

function createTextNode

Node createTextNode(
    optional DOMString data
)

Creates a new Text node.

Parameters:

  • data the text content of the node

Return: the created node

function createEvent

Event createEvent(
    CSSString eventType
)

Create a new event.

Parameters:

  • eventType specified the type of Event interface to be created

Return: the newly created Event

function getElementsByName

NodeList getElementsByName(
    optional DOMString elementName
)

Get all nodes with a certain name.

Parameters:

  • elementName the name to search for

Return: NodeList of all the elements with the name

function getElementsByTagName

NodeList getElementsByTagName(
    DOMString localName
)

Get all nodes with a certain tag.

Parameters:

  • localName the tag to search for

Return: NodeList of all the elements with the tag

function getElementById

Element getElementById(
    DOMString elementId
)

Get a element by its Id.

Parameters:

  • elementId the element id to search for

Return: the element or null

function write

void write(
    DOMString markup
)

Writes a string of text to a document stream opened by document.open()

Parameters:

  • markup A string containing the text to be written to the document.

function hasFocus

boolean hasFocus()

Indicating whether the document or any element inside the document has focus.

Return: false if the active element in the document has no focus; true if the active element in the document has focus

function getElementsByClassName

NodeList getElementsByClassName(
    DOMString classNames
)

Get all nodes with a certain class.

Parameters:

  • classNames the classes to search for

Return: NodeList of all the elements with the classes

function elementFromPoint

Element elementFromPoint(
    float x,
    float y,
    optional DOMString compositionId
)

Returns topmost element at the position.

function elementsFromPoint

sequence< Element > elementsFromPoint(
    float x,
    float y
)

Returns array of elements at the position.

function querySelector

Element querySelector(
    DOMString selectors
)

function querySelectorAll

NodeList querySelectorAll(
    DOMString selectors
)

function getSelection

Selection getSelection()

Returns a Selection object representing the range of text selected by the user, or the current position of the caret.

function caretPositionFromPoint

CaretPosition caretPositionFromPoint(
    float x,
    float y
)

Returns a CaretPosition object containing the DOM node containing the caret, and caret’s character offset within that node.

Public Attributes Documentation

variable URL

readonly attribute USVString URL;

Returns the document location as a string.

variable documentURI

readonly attribute USVString documentURI;

Returns the document location as a string.

variable origin

readonly attribute USVString origin;

Returns the document’s origin.

variable compatMode

readonly attribute DOMString compatMode;

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

variable characterSet

readonly attribute DOMString characterSet;

Returns the character encoding of the current document. The character encoding is the character set used for rendering the document, which may be different from the encoding specified by the page.

variable charset

readonly attribute DOMString charset;

historical alias of .characterSet

variable inputEncoding

readonly attribute DOMString inputEncoding;

historical alias of .characterSet

variable contentType

readonly attribute DOMString contentType;

Returns the MIME type that the document is being rendered as.

variable doctype

readonly attribute DocumentType doctype;

Returns the Document Type Declaration (DTD) associated with current document.

variable body

readonly attribute Element body;

The document body.

variable documentElement

readonly attribute Element documentElement;

The root element of the document.

variable defaultView

readonly attribute Window defaultView;

The window object associated with the document.

variable head

readonly attribute Element head;

The document head element.

variable readyState

readonly attribute DOMString readyState;

Describes the loading state of the document (loading/interactive/complete)

variable activeElement

readonly attribute Element activeElement;

The deepest element in the document through which or to which key events are being routed. This is, roughly speaking, the focused element in the document.

variable currentScript

readonly attribute HTMLScriptElement currentScript;

variable styleSheets

readonly attribute StyleSheetList styleSheets;

variable abort

attribute EventSetter abort;

variable blur

attribute EventSetter blur;

variable click

attribute EventSetter click;

variable auxclick

attribute EventSetter auxclick;

variable dblclick

attribute EventSetter dblclick;

variable error

attribute EventSetter error;

variable focus

attribute EventSetter focus;

variable keydown

attribute EventSetter keydown;

variable keypress

attribute EventSetter keypress;

variable keyup

attribute EventSetter keyup;

variable load

attribute EventSetter load;

variable mousedown

attribute EventSetter mousedown;

variable mouseover

attribute EventSetter mouseover;

variable mouseout

attribute EventSetter mouseout;

variable mouseenter

attribute EventSetter mouseenter;

variable mouseleave

attribute EventSetter mouseleave;

variable mousemove

attribute EventSetter mousemove;

variable mouseup

attribute EventSetter mouseup;

variable input

attribute EventSetter input;

variable scroll

attribute EventSetter scroll;

variable wheel

attribute EventSetter wheel;

variable touchstart

attribute EventSetter touchstart;

variable touchend

attribute EventSetter touchend;

variable touchmove

attribute EventSetter touchmove;