The Document
interface represents any web page loaded in a browser and serves as the entry point for the web page content, known as the DOM
tree. The DOM
tree contains elements like <body>
, <div>
, and many other elements. The Document
object provides global manipulation capabilities to the web page document itself and the interface describes the common properties and methods for any type of document. Depending on the document type (e.g., HTML
, XML
, SVG
, and so on), it can use additional APIs
. Furthermore, for an HTML
document using text/html
as the content type, it also implements the HTMLDocument
interface, while XML
and SVG
documents additionally implement the XMLDocument
interface.
Document()
: TheDocument
constructor creates a newDocument
object, which represents the page loaded in the browser and serves as the entry point for the page content.document.body
: Returns the<body>
element or<frameset>
element in the current document.document.characterSet
: A read-only property that returns the character encoding of the current document, which is used to render the document content and may differ from the encoding specified for the page.document.childElementCount
: A read-only property ofParentNode.childElementCount
that returns an unsigned long integer representing the number of child elements of a given element.document.children
: A read-only property that returns a dynamicHTMLCollection
of the childelements
of aNode
.document.compatMode
: Indicates whether the current document is in quirks mode, standards mode, or almost standards mode.document.contentType
: A read-only property that returns theContent-Type (MIME)
type of the current document.document.currentScript
: Thedocument.currentScript
property returns the<script>
element to which the currently running script belongs, and this property cannot be called by a script module; modules should use theimport.meta
object instead.document.defaultView
: In a browser, this property returns thewindow
object associated with the currentdocument
object, ornull
if there is none.document.designMode
: Controls whether the entire document is editable; valid values areon
andoff
, and according to the specification, this property defaults tooff
and is commonly used with<iframe>
.document.dir
: The core of thedocument.dir
is aDOMString
that represents the text direction of the document, whether it goes from left-to-right (default)ltr
or from right-to-leftrtl
, and can set the direction of the text.document.doctype
: Returns the document type definitionDTD
associated with the current document, and the returned object implements theDocumentType
interface, and aDocumentType
object can be created using theDOMImplementation.createDocumentType()
method.document.documentElement
: Read-only property that returns the root element of thedocument
object, for example, the<html>
element of anHTML
document.document.documentURI
: TheDocument
interface'sdocumentURI
property returns the location of the document as a string, and in the originalDOM3
definition, this property was read/write, but in the modernDOM
standardDOM4
, it's read-only.document.domain
: Thedomain
property of theDocument
interface gets/sets the original domain portion of the current document, often used for same-origin policy, and if this property is successfully set, the port of the original port part will also be set tonull
.document.embeds
: Theembeds
property of theDocument
interface returns a read-only list of<object>
elements embedded in the current document.document.firstElementChild
: A read-only property that returns the first child element of an object, ornull
if there are no child elements.document.forms
:document.forms
returns a collection of<form>
elements in the current document, which is anHTMLCollection
.document.mozFullScreenEnabled
: Returns a Boolean value indicating whether the browser supports full-screen mode, which is available only on pages that do not contain windowed plugins, and for a page in an<iframe>
element, it must have themozallowfullscreen
attribute.document.head
: Returns the<head>
element in the current document, or the first one if there are multiple<head>
elements.document.hidden
: Thehidden
property of thedocument
is a read-only property that returns a Boolean value, indicating whether the page istrue
(hidden) orfalse
(visible).document.images
: Read-only property that returns a collection of all theimage
elements in the current document.document.implementation
: Returns aDOMImplementation
object associated with the current document.lastElementChild
: A read-only property that returns the last childElement
of the object, ornull
if there are no child elements.document.lastModified
: Returns a string containing the date and time of the last modification of the current document.document.links
: Thedocument.links
property returns a collection of all the<area>
and<a>
elements in the document with anhref
attribute value.document.location
: Returns aLocation
object containing information about the document'sURL
and providing methods to change thisURL
and load otherURLs
.document.onbeforeunload
: This event is triggered when a page is about to unload (refresh or close).document.onload
: Triggered after the document has finished loading.document.onreadystatechange
: Triggered when thereadyState
property of the document changes.document.onvisibilitychange
: Called when thevisibilitychange
event of the object is triggered.document.onunload
: Triggered when the window unloads its content and resources.document.onerror
: Triggered when a JavaScript runtime error occurs or a resource fails to load.document.onabort
: An event handler for the abort event sent to the window, not applicable forFirefox 2
orSafari
.document.onblur
: Triggered when the window loses focus.document.onfocus
: Triggered when the window gains focus.document.onresize
: Triggered when the window size changes.document.onscroll
: Triggered when the window scrolls.document.onmessage
: Triggered when the window object receives a message event.document.onchange
: Triggered when the content of form elements in the window changes.document.oninput
: Triggered when form elements in the window receive user input.document.onreset
: Triggered when forms inside the window are reset.document.onselect
: Triggered when text in form elements inside the window is selected.document.onsubmit
: Triggered when the submit button inside a form in the window is pressed.document.onhashchange
: Triggered when the anchor hash of the window changes.document.onclick
: Triggered when the page is clicked.document.onmouseup
: Triggered when a mouse button is released.document.ondblclick
: Triggered when the page is double-clicked.document.oncontextmenu
: Triggered when the right mouse button is clicked to open the context menu.document.onmousedown
: Triggered when a mouse button is pressed.document.onmousemove
: Triggered when the mouse is moved.document.onmouseout
: Triggered when the mouse moves out of the window.document.onmouseover
: Triggered when the mouse moves into the window.document.onauxclick
: Indicates when a non-primary button on an input device is pressed, such as the middle button on a mouse.document.onkeydown
: Triggered when a keyboard key is pressed.document.onkeyup
: Triggered when a keyboard key is released.document.onkeypress
: Triggered when a keyboard key is pressed and then released.document.onanimationcancel
: Fired when a CSS animation is unexpectedly aborted, such as when theanimation-name
is changed or the animation is removed.document.onanimationend
: Fired when a CSS animation reaches the end of its active duration, as calculated by(animation-duration*animation-iteration-count) + animation-delay
.document.onanimationiteration
: Fired when a CSS animation reaches the end of each iteration, completing a single pass through the sequence of animation steps as defined by the last animation instruction.document.ondevicemotion
: Triggered when the device's motion state changes.document.ondeviceorientation
: Triggered when the device's relative orientation changes.document.ondeviceproximity
: Triggered when the device sensor detects an object approaching or moving away.document.onbeforeprint
: Fired when a page is about to start printing.document.onafterprint
: Fired when a page has started printing or the print window has closed.document.onappinstalled
: Dispatched once a web application is successfully installed as a progressive web app.document.onbeforeinstallprompt
: The event handler to be dispatched on the device when a user is about to be prompted to install a web application, and the associated event is saved for use later to prompt the user at a more opportune time.document.plugins
: A read-only property that returns anHTMLCollection
object containing one or moreHTMLEmbedElements
, representing the<embed>
elements in the current document.document.readyState
: Describes the loading status of thedocument
. When the value of this property changes, thereadystatechange
event is triggered on thedocument
object.document.referrer
: Returns aURI
representing the page from which the current page was linked or opened.document.scripts
: Returns anHTMLCollection
object containing all the<script>
elements in the current document.document.scrollingElement
: A read-only property that returns a reference to the scrollingElement
of the document; in standards mode, it returns the root element of the document, while in quirks mode, it returns theHTML body
element, and if neither exists, it returnsnull
.document.selectedStyleSheetSet
: Returns the name of the currently used style sheet set, and this property can also be used to set the current style sheet set.document.styleSheetSets
: Returns a live list of all currently available style sheet sets.document.title
: Gets or sets the title of the document.document.URL
: Returns theURL
of the current document.document.visibilityState
: A read-only property that returns the visibility of thedocument
, representing the visibility state of the current visible context of the document, indicating if the current document (page) isvisible
(at least partially visible),hidden
(invisible), or inprerender
state.
document.adoptNode(externalNode)
: Retrieves a node from anotherdocument
and removes it, along with all its descendants, from the original document (if it exists). TheownerDocument
property of the node becomes the currentdocument
, and then you can insert this node into the current document.document.close()
:document.close()
is used to end writing operations performed on the document usingdocument.write()
, which are typically initiated bydocument.open()
.document.createAttribute(name)
: Thedocument.createAttribute()
method creates and returns a new attribute node. This creates a node implementing theAttr
interface, allowing any type of attribute to be added to theDOM
.document.createCDATASection(data)
: Creates and returns a newCDATA
section node.document.createComment(data)
: Creates and returns a comment node. Thedata
is a string containing the content of the comment.document.createDocumentFragment()
: Creates a new empty document fragmentDocumentFragment
.document.createElement(tagName[, options])
: In anHTML
document, thedocument.createElement()
method is used to create anHTML
element specified by the tag nametagName
. If the user agent cannot recognizetagName
, an unknownHTML
element,HTMLUnknownElement
, will be generated.document.createElementNS(namespaceURI, qualifiedName[, options])
: Creates an element with the specified namespaceURI
and qualified name. To create an element without specifying a namespaceURI
, use thecreateElement
method.document.createEvent(type)
: Creates an event of the specified type, and the returned object must be initialized before it can be dispatched toelement.dispatchEvent
.document.createExpression(xpathText, namespaceURLMapper)
: This method compiles and generates anXPathExpression
that can be executed multiple times.document.createNodeIterator(root[, whatToShow[, filter]])
: Returns a newNodeIterator
object.document.createNSResolver(node)
: Creates anXPathNSResolver
that resolves namespaces based on definitions within the specified node's scope.document.createProcessingInstruction(target, data)
: Creates a new processing instruction node and returns it.document.createRange()
: Returns aRange
object.document.createTextNode(data)
: Creates a new text node. This method can be used to escapeHTML
characters.document.createTreeWalker(root, whatToShow, filter, entityReferenceExpansion)
: Creates and returns aTreeWalker
object.document.evaluate(xpathExpression, contextNode, namespaceResolver, resultType, result)
: Returns anXPathResult
object based on the providedXPath
expression and other parameters.document.exitFullscreen()
: Exits full-screen mode in the current document. Invoking this method will revert the document to the state before entering full-screen mode using theElement.requestFullscreen()
method.document.getElementById(id)
: Returns an element with a specificID
. Since elementID
s are generally required to be unique, this method naturally becomes an efficient way to locate a specific element.document.getElementsByClassName(names)
: Returns an array-like object containing all child elements with the specified class names. When called on thedocument
object, the entireDOM
document, including the root node, is searched. You can also call thegetElementsByClassName()
method on any element, and it will return all child elements with the specified class names, with the current element as the root node.document.getElementsByName(name)
: Returns a collection of nodes in an(X)HTML document
with the givenname
.document.getElementsByTagName(name)
: Returns anHTMLCollection
containing all elements with the given tag name. The entire document structure is searched, including the root node. The returnedHTML
collection is dynamic, meaning it automatically updates itself to stay in sync with theDOM
tree without needing to calldocument.getElementsByTagName()
again.document.getElementsByTagNameNS(namespace, name)
: Returns a collection of elements with the specified name and namespace. The entire document structure is searched, including the root node.document.hasFocus()
: Returns aBoolean
indicating whether the current document or a node within the current document has focus. This method can be used to determine whether the active element in the current document has focus.document.hasStorageAccess()
: Returns aPromise
to determine whether the document has access to first-party storage.document.importNode(externalNode, deep)
: Copies a node from an external document and then can insert this cloned node into the current document.document.open()
: Opens a document to be written to. This has several side effects, such as clearing all event listeners registered to the document, its nodes, or the window in the document. All nodes in the document are also cleared.prepend((Node or DOMString)... nodes)
: Inserts a series ofNode
objects orDOMString
objects before the first child of the parent node.document.queryCommandEnabled(command)
: Checks if the specified editing command is available in the browser.document.queryCommandSupported(command)
: Determines whether the browser supports the specified editing command.document.querySelector(selectors)
: Returns the first element in the document that matches the specified set ofCSS
selectors, as anHTMLElement
object. If no match is found, it returnsnull
. Matching is performed using depth-first pre-order traversal, starting with the first element in the document markup and then traversing in order of child nodes.document.querySelectorAll(selectors)
: Returns a staticNodeList
containingElement
objects that match at least one of the specifiedCSS
selectors, or an emptyNodeList
if no matches are found.document.releaseCapture()
: Releases mouse capture if it is currently enabled on an element within the document by callingelement.setCapture()
.document.write(markup)
: Thedocument.write()
method writes a text string to a document stream opened bydocument.open()
. Becausedocument.write
needs to write content to the document stream, ifdocument.write
is called on a document that is closed (e.g., finished loading),document.open
will automatically be invoked, clearing the content of the document.document.writeln(line)
: Writes a string of text to the document, followed by a line break.
https://github.com/WindrunnerMax/EveryDay
https://developer.mozilla.org/en/docs/Web/API/Document