AwaitedDOM / Document
Document
interface represents any web page loaded in the browser and serves as an entry point into the web page's content, which is the DOM tree. The DOM tree includes elements such as <body>
and <table>
, among many others. It provides functionality globally to the document, like how to obtain the page's URL and create new elements in the document.Properties
doc.anchors W3C {#anchors}
Returns a list of all of the anchors in the document.
Type: SuperHTMLCollection
doc.body W3C {#body}
Returns the <body>
or <frameset>
node of the current document.
Type: SuperHTMLElement
doc.characterSet W3C {#characterSet}
Returns the character set being used by the document.
Type: Promise<string>
doc.compatMode W3C {#compatMode}
Indicates whether the document is rendered in quirks or strict mode.
Type: Promise<string>
doc.contentType W3C {#contentType}
Returns the Content-Type from the MIME Header of the current document.
Type: Promise<string>
doc.cookie W3C {#cookie}
Returns a semicolon-separated list of the cookies for that document or sets a single cookie.
Type: Promise<string>
doc.designMode W3C {#designMode}
Gets/sets the ability to edit the whole document.
Type: Promise<string>
doc.dir W3C {#dir}
Gets/sets directionality (rtl/ltr) of the document.
Type: Promise<string>
doc.doctype W3C {#doctype}
Returns the Document Type Definition (DTD) of the current document.
Type: DocumentType
doc.documentElement W3C {#documentElement}
Returns the Element
that is a direct child of the document. For HTML documents, this is normally the HTMLHtmlElement
object representing the document's <html>
element.
Type: SuperElement
doc.documentURI W3C {#documentURI}
Returns the document location as a string.
Type: Promise<string>
doc.domain W3C {#domain}
Gets/sets the domain of the current document.
Type: Promise<string>
doc.embeds W3C {#embeds}
Returns a list of the embedded <embed>
elements within the current document.
Type: SuperHTMLCollection
doc.featurePolicy W3C {#featurePolicy}
Returns the FeaturePolicy
interface which provides a simple API for introspecting the feature policies applied to a specific document.
Type: FeaturePolicy
doc.forms W3C {#forms}
Returns a list of the <form>
elements within the current document.
Type: SuperHTMLCollection
doc.fullscreenEnabled W3C {#fullscreenEnabled}
Indicates whether or not full-screen mode is available.
Type: Promise<boolean>
doc.head W3C {#head}
Returns the <head>
element of the current document.
Type: HTMLHeadElement
doc.hidden W3C {#hidden}
Returns a Boolean value indicating if the page is considered hidden or not.
Type: Promise<boolean>
doc.images W3C {#images}
Returns a list of the images in the current document.
Type: SuperHTMLCollection
doc.implementation W3C {#implementation}
Returns the DOM implementation associated with the current document.
Type: DOMImplementation
doc.lastModified W3C {#lastModified}
Returns the date on which the document was last modified.
Type: Promise<string>
doc.links W3C {#links}
Returns a list of all the hyperlinks in the document.
Type: SuperHTMLCollection
doc.location W3C {#location}
Returns the URI of the current document.
Type: Location
doc.plugins W3C {#plugins}
Returns a list of the available plugins.
Type: SuperHTMLCollection
doc.readyState W3C {#readyState}
Returns loading status of the document.
Type: Promise<DocumentReadyState>
doc.referrer W3C {#referrer}
Returns the URI of the page that linked to this page.
Type: Promise<string>
doc.scripts W3C {#scripts}
Returns all the <script>
elements on the document.
Type: SuperHTMLCollection
doc.scrollingElement W3C {#scrollingElement}
Returns a reference to the Element
that scrolls the document.
Type: SuperElement
doc.title W3C {#title}
Sets or gets the title of the current document.
Type: Promise<string>
doc.URL W3C {#URL}
Returns the document location as a string.
Type: Promise<string>
doc.visibilityState W3C {#visibilityState}
Returns a string
denoting the visibility state of the document. Possible values are visible
, hidden
, prerender
, and unloaded
.
Type: Promise<VisibilityState>
doc.baseURI W3C {#baseURI}
Returns a string
representing the base URL of the document containing the Node
.
Type: Promise<string>
doc.childNodes W3C {#childNodes}
Returns a live NodeList
containing all the children of this node. NodeList
being live means that if the children of the Node
change, the NodeList
object is automatically updated.
Type: SuperNodeList
doc.firstChild W3C {#firstChild}
Returns a Node
representing the first direct child node of the node, or null
if the node has no child.
Type: SuperNode
doc.isConnected W3C {#isConnected}
A boolean indicating whether or not the Node is connected (directly or indirectly) to the context object, e.g. the Document
object in the case of the normal DOM, or the ShadowRoot
in the case of a shadow DOM.
Type: Promise<boolean>
doc.lastChild W3C {#lastChild}
Returns a Node
representing the last direct child node of the node, or null
if the node has no child.
Type: SuperNode
doc.nextSibling W3C {#nextSibling}
Returns a Node
representing the next node in the tree, or null
if there isn't such node.
Type: SuperNode
doc.nodeName W3C {#nodeName}
Returns a string
containing the name of the Node
. The structure of the name will differ with the node type. E.g. An HTMLElement
will contain the name of the corresponding tag, like 'audio'
for an HTMLAudioElement
, a Text
node will have the '#text'
string, or a Document
node will have the '#document'
string.
Type: Promise<string>
doc.nodeType W3C {#nodeType}
Returns an unsigned short
representing the type of the node. Possible values are:
Name Value ELEMENT_NODE
1
ATTRIBUTE_NODE
2
TEXT_NODE
3
CDATA_SECTION_NODE
4
ENTITY_REFERENCE_NODE
5
ENTITY_NODE
6
PROCESSING_INSTRUCTION_NODE
7
COMMENT_NODE
8
DOCUMENT_NODE
9
DOCUMENT_TYPE_NODE
10
DOCUMENT_FRAGMENT_NODE
11
NOTATION_NODE
12
Type: Promise<number>
doc.nodeValue W3C {#nodeValue}
Returns / Sets the value of the current node.
Type: Promise<string>
doc.ownerDocument W3C {#ownerDocument}
Returns the Document
that this node belongs to. If the node is itself a document, returns null
.
Type: SuperDocument
doc.parentElement W3C {#parentElement}
Returns an Element
that is the parent of this node. If the node has no parent, or if that parent is not an Element
, this property returns null
.
Type: SuperElement
doc.parentNode W3C {#parentNode}
Returns a Node
that is the parent of this node. If there is no such node, like if this node is the top of the tree or if doesn't participate in a tree, this property returns null
.
Type: SuperNode
doc.previousSibling W3C {#previousSibling}
Returns a Node
representing the previous node in the tree, or null
if there isn't such node.
Type: SuperNode
doc.textContent W3C {#textContent}
Returns / Sets the textual content of an element and all its descendants.
Type: Promise<string>
doc.activeElement W3C {#activeElement}
Returns the Element
within the shadow tree that has focus.
Type: SuperElement
doc.fullscreenElement W3C {#fullscreenElement}
Returns the Element
that's currently in full screen mode for this document.
Type: SuperElement
doc.pointerLockElement W3C {#pointerLockElement}
Returns the element set as the target for mouse events while the pointer is locked. It returns null
if lock is pending, the pointer is unlocked, or if the target is in another document.
Type: SuperElement
doc.childElementCount W3C {#childElementCount}
Returns the number of children of this ParentNode
which are elements.
Type: Promise<number>
doc.children W3C {#children}
Returns a live HTMLCollection
containing all of the Element
objects that are children of this ParentNode
, omitting all of its non-element nodes.
Type: SuperHTMLCollection
doc.firstElementChild W3C {#firstElementChild}
Returns the first node which is both a child of this ParentNode
and is also an Element
, or null
if there is none.
Type: SuperElement
doc.lastElementChild W3C {#lastElementChild}
Returns the last node which is both a child of this ParentNode
and is an Element
, or null
if there is none.
Type: SuperElement
Methods
doc.exitFullscreen*()* W3C {#exitFullscreen}
Requests that the element on this document which is currently being presented in full-screen mode be taken out of full-screen mode, restoring the previous state of the screen.
Returns: Promise<void>
doc.exitPointerLock*()* W3C {#exitPointerLock}
Release the pointer lock.
Returns: Promise<void>
doc.getElementsByClassName*(classNames)* W3C {#getElementsByClassName}
Returns a list of elements with the given class name.
Arguments:
classNames
string
. names is a string representing the class name(s) to match; multiple class names are separated by whitespace
Returns: SuperHTMLCollection
doc.getElementsByName*(elementName)* W3C {#getElementsByName}
Returns a list of elements with the given name.
Arguments:
elementName
string
. name is the value of thename
attribute of the element(s).
Returns: SuperNodeList
doc.getElementsByTagName*(qualifiedName)* W3C {#getElementsByTagName}
Returns a list of elements with the given tag name.
Arguments:
qualifiedName
string
. name is a string representing the name of the elements. The special string "*" represents all elements.
Returns: SuperHTMLCollection
doc.getElementsByTagNameNS*(namespace, localName)* W3C {#getElementsByTagNameNS}
Returns a list of elements with the given tag name and namespace.
Arguments:
namespace
string
. namespace is the namespace URI of elements to look for (seeelement.namespaceURI
).localName
string
. name is either the local name of elements to look for or the special value*
, which matches all elements (seeelement.localName
).
Returns: SuperHTMLCollection
doc.hasFocus*()* W3C {#hasFocus}
Returns true
if the focus is currently located anywhere inside the specified document.
Returns: Promise<boolean>
doc.compareDocumentPosition*(other)* W3C {#compareDocumentPosition}
Compares the position of the current node against another node in any other document.
Arguments:
other
Node
. The otherNode
with which to compare the firstnode
’s document position.
Returns: Promise<number>
doc.contains*(other)* W3C {#contains}
Returns a boolean
value indicating whether or not a node is a descendant of the calling node.
Arguments:
other
Node
. Needs content.
Returns: Promise<boolean>
doc.getRootNode*(options?)* W3C {#getRootNode}
Returns the context object's root which optionally includes the shadow root if it is available.
Arguments:
options
GetRootNodeOptions
. An object that sets options for getting the root node. The available options are:composed
: A `boolean` that indicates whether the shadow root should be returned (false
, the default), or a root node beyond shadow root (true
).
Returns: SuperNode
doc.hasChildNodes*()* W3C {#hasChildNodes}
Returns a boolean
indicating whether or not the element has any child nodes.
Returns: Promise<boolean>
doc.isDefaultNamespace*(namespace)* W3C {#isDefaultNamespace}
Accepts a namespace URI as an argument and returns a boolean
with a value of true
if the namespace is the default namespace on the given node or false
if not.
Arguments:
namespace
string
.namespaceURI
is a string representing the namespace against which the element will be checked.
Returns: Promise<boolean>
doc.isEqualNode*(otherNode)* W3C {#isEqualNode}
Returns a boolean
which indicates whether or not two nodes are of the same type and all their defining data points match.
Arguments:
otherNode
Node
.otherNode
: TheNode
to compare equality with.
Returns: Promise<boolean>
doc.isSameNode*(otherNode)* W3C {#isSameNode}
Returns a boolean
value indicating whether or not the two nodes are the same (that is, they reference the same object).
Arguments:
otherNode
Node
.otherNode
TheNode
to test against.
Returns: Promise<boolean>
doc.lookupNamespaceURI*(prefix)* W3C {#lookupNamespaceURI}
Accepts a prefix and returns the namespace URI associated with it on the given node if found (and null
if not). Supplying null
for the prefix will return the default namespace.
Arguments:
prefix
string
. The prefix to look for. If this parameter isnull
, the method will return the default namespace URI, if any.
Returns: Promise<string>
doc.lookupPrefix*(namespace)* W3C {#lookupPrefix}
Returns a string
containing the prefix for a given namespace URI, if present, and null
if not. When multiple prefixes are possible, the result is implementation-dependent.
Arguments:
namespace
string
. Needs content.
Returns: Promise<string>
doc.normalize*()* W3C {#normalize}
Clean up all the text nodes under this element (merge adjacent, remove empty).
Returns: Promise<void>
doc.caretPositionFromPoint*(x, y)* W3C {#caretPositionFromPoint}
Returns a CaretPosition
object containing the DOM node containing the caret, and caret's character offset within that node.
Arguments:
x
number
. The horizontal coordinate of a point.y
number
. The vertical coordinate of a point.
Returns: CaretPosition
doc.elementFromPoint*(x, y)* W3C {#elementFromPoint}
Returns the topmost element at the specified coordinates.
Arguments:
x
number
. The horizontal coordinate of a point, relative to the left edge of the current viewport.y
number
. The vertical coordinate of a point, relative to the top edge of the current viewport.
Returns: SuperElement
doc.getSelection*()* W3C {#getSelection}
Returns a Selection
object representing the range of text selected by the user, or the current position of the caret.
Returns: Selection
doc.getElementById*(elementId)* W3C {#getElementById}
Needs content.
Arguments:
elementId
string
. Needs content.
Returns: SuperElement
doc.querySelector*(selectors)* W3C {#querySelector}
Returns the first Element
with the current element as root that matches the specified group of selectors.
Arguments:
selectors
string
. Astring
containing one or more selectors to match against. This string must be a valid compound selector list supported by the browser; if it's not, aSyntaxError
exception is thrown. See Locating DOM elements using selectors for more information about using selectors to identify elements. Multiple selectors may be specified by separating them using commas.
Returns: SuperElement
doc.querySelectorAll*(selectors)* W3C {#querySelectorAll}
Returns a NodeList
representing a list of elements with the current element as root that matches the specified group of selectors.
Arguments:
selectors
string
. Astring
containing one or more selectors to match against. This string must be a valid CSS selector string; if it's not, aSyntaxError
exception is thrown. See Locating DOM elements using selectors for more information about using selectors to identify elements. Multiple selectors may be specified by separating them using commas.
Returns: SuperNodeList
doc.createExpression*(expression, resolver?)* W3C {#createExpression}
Creates a parsed XPath expression with resolved namespaces.
Arguments:
expression
string
. Astring
representing representing the XPath expression to be created.resolver
XPathNSResolver
. Permits translation of all prefixes, including thexml
namespace prefix, within the XPath expression into appropriate namespace URIs.
Returns: XPathExpression
doc.evaluate*(expression, contextNode, resolver?, type?, result?)* W3C {#evaluate}
Evaluates an XPath expression string and returns a result of the specified type if possible.
Arguments:
expression
string
. Astring
representing the XPath expression to be parsed and evaluated.contextNode
Node
. ANode
representing the context to use for evaluating the expression.resolver
XPathNSResolver
. Permits translation of all prefixes, including thexml
namespace prefix, within the XPath expression into appropriate namespace URIs.type
number
. Specifies the type of result to be returned by evaluating the expression. This must be one of theXPathResult.Constants
.result
XPathResult
. Allows to specify a result object which may be reused and returned by this method. If this is specified asnull
or the implementation does not reuse the specified result, a new result object will be returned.
Returns: XPathResult
Unimplemented Specs
Properties
defaultView | fonts |
onfullscreenchange | onfullscreenerror |
onpointerlockchange | onpointerlockerror |
onreadystatechange | onvisibilitychange |
oncopy | oncut |
onpaste | fonts |
onabort | onanimationend |
onanimationiteration | onanimationstart |
onauxclick | onblur |
oncancel | oncanplay |
oncanplaythrough | onchange |
onclick | onclose |
oncontextmenu | oncuechange |
ondblclick | ondrag |
ondragend | ondragenter |
ondragleave | ondragover |
ondragstart | ondrop |
ondurationchange | onemptied |
onended | onerror |
onfocus | onformdata |
ongotpointercapture | oninput |
oninvalid | onkeydown |
onkeypress | onkeyup |
onload | onloadeddata |
onloadedmetadata | onloadstart |
onlostpointercapture | onmousedown |
onmouseenter | onmouseleave |
onmousemove | onmouseout |
onmouseover | onmouseup |
onpause | onplay |
onplaying | onpointercancel |
onpointerdown | onpointerenter |
onpointerleave | onpointermove |
onpointerout | onpointerover |
onpointerup | onprogress |
onratechange | onreset |
onresize | onscroll |
onseeked | onseeking |
onselect | onselectionchange |
onselectstart | onstalled |
onsubmit | onsuspend |
ontimeupdate | ontouchcancel |
ontouchend | ontouchmove |
ontouchstart | ontransitionend |
onvolumechange | onwaiting |
onwheel |
Methods
adoptNode() | captureEvents() |
close() | createAttribute() |
createAttributeNS() | createCDATASection() |
createComment() | createDocumentFragment() |
createElement() | createElementNS() |
createEvent() | createNodeIterator() |
createProcessingInstruction() | createRange() |
createTextNode() | createTreeWalker() |
getSelection() | importNode() |
open() | releaseEvents() |
write() | writeln() |
appendChild() | cloneNode() |
insertBefore() | removeChild() |
replaceChild() | addEventListener() |
dispatchEvent() | removeEventListener() |
elementsFromPoint() | append() |
prepend() | createNSResolver() |