The 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.
The Document
interface describes the common properties and methods for any kind of document. Depending on the document's type (e.g. HTML, XML, SVG, …), a larger API is available: HTML documents, served with the text/html
content type, also implement the HTMLDocument
interface, whereas XML and SVG documents implement the XMLDocument
interface.
Document()
Document
object.This interface also inherits from the Node
and EventTarget
interfaces.
Document.all
Document.async
Document.load
to indicate an asynchronous request.Document.characterSet
Read only
Document.charset
Read only
Document.characterSet
. Use this property instead.Document.compatMode
Read only
Document.contentType
Read only
Document.doctype
Read only
Document.documentElement
Read only
Element
that is a direct child of the document. For HTML documents, this is normally the <html>
element.Document.documentURI
Read only
Document.domConfig
DOMConfiguration
object.Document.fullscreen
true
when the document is in full-screen mode
.Document.hidden
Read only
Document.implementation
Read only
Document.inputEncoding
Read only
Document.characterSet
. Use this property instead.Document.lastStyleSheetSet
Read only
null
until the style sheet is changed by setting the value of selectedStyleSheetSet
.Document.mozSyntheticDocument
Boolean
that is true
only if this document is synthetic, such as a standalone image, video, audio file, or the like.Document.mozFullScreenElement
Read only Document.mozFullScreenEnabled
Read only true
if calling Element.mozRequestFullscreen()
would succeed in the curent document.Document.pointerLockElement
Read only
null
if lock is pending, pointer is unlocked, or if the target is in another document.Document.preferredStyleSheetSet
Read only
Document.scrollingElement
Read only
Element
that scrolls the document.Document.selectedStyleSheetSet
Document.styleSheets
Read only
Document.styleSheetSets
Read only
Document.timeline
Read only
Document.undoManager
Read only
Document.visibilityState
Read only
Returns a string
denoting the visibility state of the document. Possible values are visible
, hidden
, prerender
, and unloaded
.
Document.xmlEncoding
Document.xmlStandalone
Obsolete since Gecko 10.0
true
if the XML declaration specifies the document to be standalone (e.g., An external part of the DTD affects the document's content), else false
.Document.xmlVersion
Obsolete since Gecko 10.0
"1.0"
if the declaration is absent.The Document
interface is extended with the ParentNode
interface:
ParentNode.children
Read only
HTMLCollection
containing all objects of type Element
that are children of this ParentNode
.ParentNode.firstElementChild
Read only
Element
that is the first child of this ParentNode
, or null
if there is none.ParentNode.lastElementChild
Read only
Element
that is the last child of this ParentNode
, or null
if there is none.ParentNode.childElementCount
Read only
unsigned long
giving the amount of children that the object has.The Document
interface for HTML documents inherits from the HTMLDocument
interface or, since HTML5, is extended for such documents.
Document.activeElement
Read only
Document.alinkColor
Document.anchors
Document.applets
Document.bgColor
Document.body
<body>
element of the current document.Document.cookie
Document.defaultView
Read only
Document.designMode
Document.dir
Read only
Document.domain
Document.embeds
Read only
<embed>
elements within the current document.document.fgColor
Document.forms
Read only
<form>
elements within the current document.Document.head
Read only
<head>
element of the current document.Document.height
Document.images
Read only
Document.lastModified
Read only
Document.linkColor
Document.links
Read only
Document.location
Read only
Document.plugins
Read only
Document.readyState
Read only Document.referrer
Read only
Document.scripts
Read only
<script>
elements on the document.Document.title
Document.URL
Read only
Document.vlinkColor
Document.width
Document.onafterscriptexecute
afterscriptexecute
event.Document.onbeforescriptexecute
beforescriptexecute
event.Document.oncopy
copy
event.Document.oncut
cut
event.Document.onfullscreenchange
EventHandler
representing the code to be called when the fullscreenchange
event is raised.Document.onfullscreenerror
EventHandler
representing the code to be called when the fullscreenerror
event is raised.Document.onpaste
paste
event.Document.onpointerlockchange
pointerlockchange
event.Document.onpointerlockerror
pointerlockerror
event.Document.onreadystatechange
readystatechange
event.Document.onselectionchange
EventHandler
representing the code to be called when the selectionchange
event is raised.Document.onvisibilitychange
EventHandler
representing the code to be called when the visibilitychange
event is raised.Document.onwheel
wheel
event.The Document
interface is extended with the GlobalEventHandlers
interface:
GlobalEventHandlers.onabort
EventHandler
representing the code to be called when the abort
event is raised.GlobalEventHandlers.onanimationcancel
EventHandler
called when an animationcancel
event is sent, indicating that a running CSS animation has been canceled.GlobalEventHandlers.onanimationend
EventHandler
called when an animationend
event is sent, indicating that a CSS animation has stopped playing.GlobalEventHandlers.onanimationiteration
EventHandler
called when an animationiteration
event has been sent, indicating that a CSS animation has begun playing a new iteration of the animation sequence.GlobalEventHandlers.onanimationstart
EventHandler
called when an animationstart
event is sent, indicating that a CSS animation has started playing.GlobalEventHandlers.onauxclick
EventHandler
called when an auxclick
event is sent, indicating that a non-primary button has been pressed on an input device (e.g. a middle mouse button).GlobalEventHandlers.onblur
EventHandler
representing the code to be called when the blur
event is raised.GlobalEventHandlers.onerror
OnErrorEventHandler
representing the code to be called when the error
event is raised.GlobalEventHandlers.onfocus
EventHandler
representing the code to be called when the focus
event is raised.GlobalEventHandlers.oncancel
EventHandler
representing the code to be called when the cancel
event is raised.GlobalEventHandlers.oncanplay
EventHandler
representing the code to be called when the canplay
event is raised.GlobalEventHandlers.oncanplaythrough
EventHandler
representing the code to be called when the canplaythrough
event is raised.GlobalEventHandlers.onchange
EventHandler
representing the code to be called when the change
event is raised.GlobalEventHandlers.onclick
EventHandler
representing the code to be called when the click
event is raised.GlobalEventHandlers.onclose
EventHandler
representing the code to be called when the close
event is raised.GlobalEventHandlers.oncontextmenu
EventHandler
representing the code to be called when the contextmenu
event is raised.GlobalEventHandlers.oncuechange
EventHandler
representing the code to be called when the cuechange
event is raised.GlobalEventHandlers.ondblclick
EventHandler
representing the code to be called when the dblclick
event is raised.GlobalEventHandlers.ondrag
EventHandler
representing the code to be called when the drag
event is raised.GlobalEventHandlers.ondragend
EventHandler
representing the code to be called when the dragend
event is raised.GlobalEventHandlers.ondragenter
EventHandler
representing the code to be called when the dragenter
event is raised.GlobalEventHandlers.ondragexit
EventHandler
representing the code to be called when the dragexit
event is raised.GlobalEventHandlers.ondragleave
EventHandler
representing the code to be called when the dragleave
event is raised.GlobalEventHandlers.ondragover
EventHandler
representing the code to be called when the dragover
event is raised.GlobalEventHandlers.ondragstart
EventHandler
representing the code to be called when the dragstart
event is raised.GlobalEventHandlers.ondrop
EventHandler
representing the code to be called when the drop
event is raised.GlobalEventHandlers.ondurationchange
EventHandler
representing the code to be called when the durationchange
event is raised.GlobalEventHandlers.onemptied
EventHandler
representing the code to be called when the emptied
event is raised.GlobalEventHandlers.onended
EventHandler
representing the code to be called when the ended
event is raised.GlobalEventHandlers.ongotpointercapture
Is an EventHandler
representing the code to be called when the gotpointercapture
event type is raised.
GlobalEventHandlers.oninput
EventHandler
representing the code to be called when the input
event is raised.GlobalEventHandlers.oninvalid
EventHandler
representing the code to be called when the invalid
event is raised.GlobalEventHandlers.onkeydown
EventHandler
representing the code to be called when the keydown
event is raised.GlobalEventHandlers.onkeypress
EventHandler
representing the code to be called when the keypress
event is raised.GlobalEventHandlers.onkeyup
EventHandler
representing the code to be called when the keyup
event is raised.GlobalEventHandlers.onload
EventHandler
representing the code to be called when the load
event is raised.GlobalEventHandlers.onloadeddata
EventHandler
representing the code to be called when the loadeddata
event is raised.GlobalEventHandlers.onloadedmetadata
EventHandler
representing the code to be called when the loadedmetadata
event is raised.GlobalEventHandlers.onloadend
EventHandler
representing the code to be called when the loadend
event is raised (when progress has stopped on the loading of a resource.)GlobalEventHandlers.onloadstart
EventHandler
representing the code to be called when the loadstart
event is raised (when progress has begun on the loading of a resource.)GlobalEventHandlers.onlostpointercapture
Is an EventHandler
representing the code to be called when the lostpointercapture
event type is raised.
GlobalEventHandlers.onmousedown
EventHandler
representing the code to be called when the mousedown
event is raised.GlobalEventHandlers.onmouseenter
EventHandler
representing the code to be called when the mouseenter
event is raised.GlobalEventHandlers.onmouseleave
EventHandler
representing the code to be called when the mouseleave
event is raised.GlobalEventHandlers.onmousemove
EventHandler
representing the code to be called when the mousemove
event is raised.GlobalEventHandlers.onmouseout
EventHandler
representing the code to be called when the mouseout
event is raised.GlobalEventHandlers.onmouseover
EventHandler
representing the code to be called when the mouseover
event is raised.GlobalEventHandlers.onmouseup
EventHandler
representing the code to be called when the mouseup
event is raised.GlobalEventHandlers.onmousewheel
EventHandler
representing the code to be called when the mousewheel
event is raised.GlobalEventHandlers.onwheel
EventHandler
representing the code to be called when the wheel
event is raised.GlobalEventHandlers.onpause
EventHandler
representing the code to be called when the pause
event is raised.GlobalEventHandlers.onplay
EventHandler
representing the code to be called when the play
event is raised.GlobalEventHandlers.onplaying
EventHandler
representing the code to be called when the playing
event is raised.GlobalEventHandlers.onpointerdown
EventHandler
representing the code to be called when the pointerdown
event is raised.GlobalEventHandlers.onpointermove
EventHandler
representing the code to be called when the pointermove
event is raised.GlobalEventHandlers.onpointerup
EventHandler
representing the code to be called when the pointerup
event is raised.GlobalEventHandlers.onpointercancel
EventHandler
representing the code to be called when the pointercancel
event is raised.GlobalEventHandlers.onpointerover
EventHandler
representing the code to be called when the pointerover
event is raised.GlobalEventHandlers.onpointerout
EventHandler
representing the code to be called when the pointerout
event is raised.GlobalEventHandlers.onpointerenter
EventHandler
representing the code to be called when the pointerevent
event is raised.GlobalEventHandlers.onpointerleave
EventHandler
representing the code to be called when the pointerleave
event is raised.GlobalEventHandlers.onpointerlockchange
EventHandler
representing the code to be called when the pointerlockchange
event is raised.GlobalEventHandlers.onpointerlockerror
EventHandler
representing the code to be called when the pointerlockerror
event is raised.GlobalEventHandlers.onprogress
EventHandler
representing the code to be called when the progress
event is raised.GlobalEventHandlers.onratechange
EventHandler
representing the code to be called when the ratechange
event is raised.GlobalEventHandlers.onreset
EventHandler
representing the code to be called when the reset
event is raised.GlobalEventHandlers.onscroll
EventHandler
representing the code to be called when the scroll
event is raised.GlobalEventHandlers.onseeked
EventHandler
representing the code to be called when the seeked
event is raised.GlobalEventHandlers.onseeking
EventHandler
representing the code to be called when the seeking
event is raised.GlobalEventHandlers.onselect
EventHandler
representing the code to be called when the select
event is raised.GlobalEventHandlers.onselectstart
EventHandler
representing the code to be called when the selectionchange
event is raised, i.e. when the user starts to make a new text selection on a web page.GlobalEventHandlers.onselectionchange
EventHandler
representing the code to be called when the selectionchange
event is raised, i.e. when the text selected on a web page changes.GlobalEventHandlers.onshow
EventHandler
representing the code to be called when the show
event is raised.GlobalEventHandlers.onsort
EventHandler
representing the code to be called when the sort
event is raised.GlobalEventHandlers.onstalled
EventHandler
representing the code to be called when the stalled
event is raised.GlobalEventHandlers.onsubmit
EventHandler
representing the code to be called when the submit
event is raised.GlobalEventHandlers.onsuspend
EventHandler
representing the code to be called when the suspend
event is raised.GlobalEventHandlers.ontimeupdate
EventHandler
representing the code to be called when the timeupdate
event is raised.GlobalEventHandlers.onvolumechange
EventHandler
representing the code to be called when the volumechange
event is raised.GlobalEventHandlers.ontouchcancel
EventHandler
representing the code to be called when the touchcancel
event is raised.GlobalEventHandlers.ontouchend
EventHandler
representing the code to be called when the touchend
event is raised.GlobalEventHandlers.ontouchmove
EventHandler
representing the code to be called when the touchmove
event is raised.GlobalEventHandlers.ontouchstart
EventHandler
representing the code to be called when the touchstart
event is raised.GlobalEventHandlers.ontransitioncancel
EventHandler
called when a transitioncancel
event is sent, indicating that a CSS transition has been cancelled.GlobalEventHandlers.ontransitionend
EventHandler
called when a transitionend
event is sent, indicating that a CSS transition has finished playing.GlobalEventHandlers.onwaiting
EventHandler
representing the code to be called when the waiting
event is raised.This interface also inherits from the Node
and EventTarget
interfaces.
Document.adoptNode()
Document.captureEvents()
Window.captureEvents
.Document.caretPositionFromPoint()
CaretPosition
at or near the specified coordinates.Document.caretRangeFromPoint()
Range
object for the document fragment under the specified coordinates.Document.createAttribute()
Attr
object and returns it.Document.createAttributeNS()
Document.createCDATASection()
Document.createComment()
Document.createDocumentFragment()
Document.createElement()
Document.createElementNS()
Document.createEntityReference()
Document.createEvent()
Document.createNodeIterator()
NodeIterator
object.Document.createProcessingInstruction()
ProcessingInstruction
object.Document.createRange()
Range
object.Document.createTextNode()
Document.createTouch()
Touch
object.Document.createTouchList()
TouchList
object.Document.createTreeWalker()
TreeWalker
object.Document.elementFromPoint()
Document.elementsFromPoint()
Document.enableStyleSheetsForSet()
Document.exitPointerLock()
Document.getAnimations()
Animation
objects currently in effect, whose target elements are descendants of the document
.Document.getElementsByClassName()
Document.getElementsByTagName()
Document.getElementsByTagNameNS()
Document.importNode()
Document.normalizeDocument()
Document.registerElement()
Document.releaseCapture()
Document.releaseEvents()
Window.releaseEvents()
.Document.routeEvent()
Obsolete since Gecko 24
Window.routeEvent()
.Document.mozSetImageElement()
The Document
interface is extended with the ParentNode
interface:
document.getElementById(String id)
document.querySelector(String selector)
document.querySelectorAll(String selector)
The Document
interface is extended with the XPathEvaluator
interface:
document.createExpression(String expression, XPathNSResolver resolver)
XPathExpression
which can then be used for (repeated) evaluations.document.createNSResolver(Node resolver)
XPathNSResolver
object.document.evaluate(String expression, Node contextNode, XPathNSResolver resolver, Number type, Object result)
The Document
interface for HTML documents inherit from the HTMLDocument
interface or, since HTML5, is extended for such documents:
document.clear()
document.close()
document.execCommand(String command[, Boolean showUI[, String value]])
document.getElementsByName(String name)
document.getSelection()
Selection
object related to text selected in the document.document.hasFocus()
true
if the focus is currently located anywhere inside the specified document.document.open()
document.queryCommandEnabled(String command)
document.queryCommandIndeterm(String command)
document.queryCommandState(String command)
document.queryCommandSupported(String command)
document.queryCommandValue(String command)
document.write(String text)
document.writeln(String text)
Mozilla defines a set of non-standard properties made only for XUL content:
document.currentScript
<script>
element that is currently executing.document.documentURIObject
nsIURI
object representing the URI of the document. This property only has special meaning in privileged JavaScript code (with UniversalXPConnect privileges).document.popupNode
document.tooltipNode
Mozilla also define some non-standard methods:
document.execCommandShowHelp
Obsolete since Gecko 14.0
document.getBoxObjectFor
Element.getBoundingClientRect()
method instead.document.loadOverlay
document.queryCommandText
Obsolete since Gecko 14.0
Microsoft defines some non-standard properties:
document.fileSize
*
Node
interface in the Document
interface:document.contains
document.body.contains()
can be used.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Document