Document

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. HTMLXML, 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.

Constructor

Document()Creates a new Document object.

Properties

This interface also inherits from the Node and EventTarget interfaces.Document.anchorsRead onlyReturns a list of all of the anchors in the document.Document.bodyReturns the <body> or <frameset> node of the current document.Document.characterSetRead onlyReturns the character set being used by the document.Document.compatMode Read onlyIndicates whether the document is rendered in quirks or strict mode.Document.contentType Read onlyReturns the Content-Type from the MIME Header of the current document.Document.doctypeRead onlyReturns the Document Type Definition (DTD) of the current document.Document.documentElementRead onlyReturns 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.Document.documentURIRead onlyReturns the document location as a string.Document.embedsRead onlyReturns a list of the embedded <embed> elements within the current document.Document.fontsReturns the FontFaceSet interface of the current document.Document.formsRead onlyReturns a list of the <form> elements within the current document.Document.headRead onlyReturns the <head> element of the current document.Document.hiddenRead onlyReturns a Boolean value indicating if the page is considered hidden or not.Document.imagesRead onlyReturns a list of the images in the current document.Document.implementationRead onlyReturns the DOM implementation associated with the current document.Document.lastStyleSheetSetRead onlyReturns the name of the style sheet set that was last enabled. Has the value null until the style sheet is changed by setting the value of selectedStyleSheetSet.Document.linksRead onlyReturns a list of all the hyperlinks in the document.Document.mozSyntheticDocument Returns a Boolean that is true only if this document is synthetic, such as a standalone image, video, audio file, or the like.Document.pictureInPictureEnabledRead onlyReturns true if the picture-in-picture feature is enabledDocument.pluginsRead onlyReturns a list of the available plugins.Document.featurePolicy Read onlyReturns the FeaturePolicy interface which provides a simple API for introspecting the feature policies applied to a specific document.Document.preferredStyleSheetSetRead onlyReturns the preferred style sheet set as specified by the page author.Document.scriptsRead onlyReturns all the <script> elements on the document.Document.scrollingElementRead onlyReturns a reference to the Element that scrolls the document.Document.selectedStyleSheetSetReturns which style sheet set is currently in use.Document.styleSheetSetsRead onlyReturns a list of the style sheet sets available on the document.Document.timelineRead onlyReturns timeline as a special instance of DocumentTimeline that is automatically created on page load.Document.undoManager Read only…Document.visibilityStateRead onlyReturns a string denoting the visibility state of the document. Possible values are visiblehiddenprerender, and unloaded.

The Document interface is extended with the ParentNode interface:ParentNode.childElementCount Read onlyReturns the number of children of this ParentNode which are elements.ParentNode.children Read onlyReturns a live HTMLCollection containing all of the Element objects that are children of this ParentNode, omitting all of its non-element nodes.ParentNode.firstElementChild Read onlyReturns the first node which is both a child of this ParentNodeand is also an Element, or null if there is none.ParentNode.lastElementChild Read onlyReturns the last node which is both a child of this ParentNodeand is an Element, or null if there is none.

Extensions for HTMLDocument

The Document interface for HTML documents inherits from the HTMLDocument interface or, since HTML5, is extended for such documents.Document.cookieReturns a semicolon-separated list of the cookies for that document or sets a single cookie.Document.defaultViewRead onlyReturns a reference to the window object.Document.designModeGets/sets the ability to edit the whole document.Document.dirRead onlyGets/sets directionality (rtl/ltr) of the document.Document.domainGets/sets the domain of the current document.Document.lastModifiedRead onlyReturns the date on which the document was last modified.Document.locationRead onlyReturns the URI of the current document.Document.readyStateRead onlyReturns loading status of the document.Document.referrerRead onlyReturns the URI of the page that linked to this page.Document.titleSets or gets the title of the current document.Document.URLRead onlyReturns the document location as a string.

Properties included from DocumentOrShadowRoot

The Document interface includes the following properties defined on the DocumentOrShadowRoot mixin. Note that this is currently only implemented by Chrome; other browsers still implement them directly on the Document interface.DocumentOrShadowRoot.activeElementRead onlyReturns the Element within the shadow tree that has focus.Document.fullscreenElementRead onlyThe element that’s currently in full screen mode for this document.DocumentOrShadowRoot.pointerLockElement Read onlyReturns the element set as the target for mouse events while the pointer is locked. null if lock is pending, pointer is unlocked, or if the target is in another document.DocumentOrShadowRoot.styleSheetsRead onlyReturns a StyleSheetList of CSSStyleSheet objects for stylesheets explicitly linked into, or embedded in a document.

Event handlers

Document.onafterscriptexecute Represents the event handling code for the afterscriptexecute event.Document.onbeforescriptexecute Represents the event handling code for the beforescriptexecute event.Document.oncopy Represents the event handling code for the copy event.Document.oncut Represents the event handling code for the cut event.Document.onfullscreenchangeIs an EventHandler representing the code to be called when the fullscreenchange event is raised.Document.onfullscreenerrorIs an EventHandler representing the code to be called when the fullscreenerror event is raised.Document.onpaste Represents the event handling code for the paste event.Document.onreadystatechangeRepresents the event handling code for the readystatechange event.Document.onselectionchange Is an EventHandler representing the code to be called when the selectionchange event is raised.Document.onvisibilitychangeIs an EventHandler representing the code to be called when the visibilitychange event is raised.

The Document interface is extended with the GlobalEventHandlers interface:GlobalEventHandlers.onabortIs an EventHandler representing the code to be called when the abort event is raised.GlobalEventHandlers.onanimationcancel An EventHandler called when an animationcancel event is sent, indicating that a running CSS animation has been canceled.GlobalEventHandlers.onanimationend An EventHandler called when an animationend event is sent, indicating that a CSS animation has stopped playing.GlobalEventHandlers.onanimationiteration An 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 An EventHandler called when an animationstart event is sent, indicating that a CSS animation has started playing.GlobalEventHandlers.onauxclick An 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.onblurIs an EventHandler representing the code to be called when the blur event is raised.GlobalEventHandlers.onerrorIs an OnErrorEventHandler representing the code to be called when the error event is raised.GlobalEventHandlers.onfocusIs an EventHandler representing the code to be called when the focus event is raised.GlobalEventHandlers.oncancelIs an EventHandler representing the code to be called when the cancel event is raised.GlobalEventHandlers.oncanplayIs an EventHandler representing the code to be called when the canplay event is raised.GlobalEventHandlers.oncanplaythroughIs an EventHandler representing the code to be called when the canplaythrough event is raised.GlobalEventHandlers.onchangeIs an EventHandler representing the code to be called when the change event is raised.GlobalEventHandlers.onclickIs an EventHandler representing the code to be called when the click event is raised.GlobalEventHandlers.oncloseIs an EventHandler representing the code to be called when the close event is raised.GlobalEventHandlers.oncontextmenuIs an EventHandler representing the code to be called when the contextmenu event is raised.GlobalEventHandlers.oncuechangeIs an EventHandler representing the code to be called when the cuechange event is raised.GlobalEventHandlers.ondblclickIs an EventHandler representing the code to be called when the dblclick event is raised.GlobalEventHandlers.ondragIs an EventHandler representing the code to be called when the drag event is raised.GlobalEventHandlers.ondragendIs an EventHandler representing the code to be called when the dragend event is raised.GlobalEventHandlers.ondragenterIs an EventHandler representing the code to be called when the dragenter event is raised.GlobalEventHandlers.ondragexitIs an EventHandler representing the code to be called when the dragexit event is raised.GlobalEventHandlers.ondragleaveIs an EventHandler representing the code to be called when the dragleave event is raised.GlobalEventHandlers.ondragoverIs an EventHandler representing the code to be called when the dragover event is raised.GlobalEventHandlers.ondragstartIs an EventHandler representing the code to be called when the dragstart event is raised.GlobalEventHandlers.ondropIs an EventHandler representing the code to be called when the drop event is raised.GlobalEventHandlers.ondurationchangeIs an EventHandler representing the code to be called when the durationchange event is raised.GlobalEventHandlers.onemptiedIs an EventHandler representing the code to be called when the emptied event is raised.GlobalEventHandlers.onendedIs an EventHandler representing the code to be called when the ended event is raised.GlobalEventHandlers.onformdataIs an EventHandler for processing formdata events, fired after the entry list representing the form’s data is constructed.GlobalEventHandlers.ongotpointercaptureIs an EventHandler representing the code to be called when the gotpointercapture event type is raised.GlobalEventHandlers.oninputIs an EventHandler representing the code to be called when the input event is raised.GlobalEventHandlers.oninvalidIs an EventHandler representing the code to be called when the invalid event is raised.GlobalEventHandlers.onkeydownIs an EventHandler representing the code to be called when the keydown event is raised.GlobalEventHandlers.onkeypressIs an EventHandler representing the code to be called when the keypress event is raised.GlobalEventHandlers.onkeyupIs an EventHandler representing the code to be called when the keyup event is raised.GlobalEventHandlers.onloadIs an EventHandler representing the code to be called when the load event is raised.GlobalEventHandlers.onloadeddataIs an EventHandler representing the code to be called when the loadeddata event is raised.GlobalEventHandlers.onloadedmetadataIs an EventHandler representing the code to be called when the loadedmetadata event is raised.GlobalEventHandlers.onloadendIs an EventHandler representing the code to be called when the loadend event is raised (when progress has stopped on the loading of a resource.)GlobalEventHandlers.onloadstartIs an EventHandler representing the code to be called when the loadstart event is raised (when progress has begun on the loading of a resource.)GlobalEventHandlers.onlostpointercaptureIs an EventHandler representing the code to be called when the lostpointercapture event type is raised.GlobalEventHandlers.onmousedownIs an EventHandler representing the code to be called when the mousedown event is raised.GlobalEventHandlers.onmouseenterIs an EventHandler representing the code to be called when the mouseenter event is raised.GlobalEventHandlers.onmouseleaveIs an EventHandler representing the code to be called when the mouseleave event is raised.GlobalEventHandlers.onmousemoveIs an EventHandler representing the code to be called when the mousemove event is raised.GlobalEventHandlers.onmouseoutIs an EventHandler representing the code to be called when the mouseout event is raised.GlobalEventHandlers.onmouseoverIs an EventHandler representing the code to be called when the mouseover event is raised.GlobalEventHandlers.onmouseupIs an EventHandler representing the code to be called when the mouseup event is raised.GlobalEventHandlers.onmousewheel  Is an EventHandler representing the code to be called when the mousewheel event is raised. Deprecated. Use onwheel instead.GlobalEventHandlers.onwheelIs an EventHandler representing the code to be called when the wheel event is raised.GlobalEventHandlers.onpauseIs an EventHandler representing the code to be called when the pause event is raised.GlobalEventHandlers.onplayIs an EventHandler representing the code to be called when the play event is raised.GlobalEventHandlers.onplayingIs an EventHandler representing the code to be called when the playing event is raised.GlobalEventHandlers.onpointerdownIs an EventHandler representing the code to be called when the pointerdown event is raised.GlobalEventHandlers.onpointermoveIs an EventHandler representing the code to be called when the pointermove event is raised.GlobalEventHandlers.onpointerupIs an EventHandler representing the code to be called when the pointerup event is raised.GlobalEventHandlers.onpointercancelIs an EventHandler representing the code to be called when the pointercancel event is raised.GlobalEventHandlers.onpointeroverIs an EventHandler representing the code to be called when the pointerover event is raised.GlobalEventHandlers.onpointeroutIs an EventHandler representing the code to be called when the pointerout event is raised.GlobalEventHandlers.onpointerenterIs an EventHandler representing the code to be called when the pointerenter event is raised.GlobalEventHandlers.onpointerleaveIs an EventHandler representing the code to be called when the pointerleave event is raised.GlobalEventHandlers.onpointerlockchange Is an EventHandler representing the code to be called when the pointerlockchange event is raised.GlobalEventHandlers.onpointerlockerror Is an EventHandler representing the code to be called when the pointerlockerror event is raised.GlobalEventHandlers.onprogressIs an EventHandler representing the code to be called when the progress event is raised.GlobalEventHandlers.onratechangeIs an EventHandler representing the code to be called when the ratechange event is raised.GlobalEventHandlers.onresetIs an EventHandler representing the code to be called when the reset event is raised.GlobalEventHandlers.onresizeIs an EventHandler representing the code to be called when the resize event is raised.GlobalEventHandlers.onscrollIs an EventHandler representing the code to be called when the scroll event is raised.GlobalEventHandlers.onseekedIs an EventHandler representing the code to be called when the seeked event is raised.GlobalEventHandlers.onseekingIs an EventHandler representing the code to be called when the seeking event is raised.GlobalEventHandlers.onselectIs an EventHandler representing the code to be called when the select event is raised.GlobalEventHandlers.onselectstartIs an 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.onselectionchangeIs an 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.onshowIs an EventHandler representing the code to be called when the show event is raised.GlobalEventHandlers.onsort Is an EventHandler representing the code to be called when the sort event is raised.GlobalEventHandlers.onstalledIs an EventHandler representing the code to be called when the stalled event is raised.GlobalEventHandlers.onsubmitIs an EventHandler representing the code to be called when the submit event is raised.GlobalEventHandlers.onsuspendIs an EventHandler representing the code to be called when the suspend event is raised.GlobalEventHandlers.ontimeupdateIs an EventHandler representing the code to be called when the timeupdate event is raised.GlobalEventHandlers.onvolumechangeIs an EventHandler representing the code to be called when the volumechange event is raised.GlobalEventHandlers.ontouchcancel  Is an EventHandler representing the code to be called when the touchcancel event is raised.GlobalEventHandlers.ontouchend  Is an EventHandler representing the code to be called when the touchend event is raised.GlobalEventHandlers.ontouchmove  Is an EventHandler representing the code to be called when the touchmove event is raised.GlobalEventHandlers.ontouchstart  Is an EventHandler representing the code to be called when the touchstart event is raised.GlobalEventHandlers.ontransitioncancelAn EventHandler called when a transitioncancel event is sent, indicating that a CSS transition has been cancelled.GlobalEventHandlers.ontransitionendAn EventHandler called when a transitionend event is sent, indicating that a CSS transition has finished playing.GlobalEventHandlers.ontransitionrunAn EventHandler called when a transitionrun event is sent, indicating that a CSS transition is running, though not nessarilty started.GlobalEventHandlers.ontransitionstartAn EventHandler called when a transitionstart event is sent, indicating that a CSS transition has started transitioning.GlobalEventHandlers.onwaitingIs an EventHandler representing the code to be called when the waiting event is raised.

Deprecated properties

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

Document.all  Provides access to all elements in the document — it returns an HTMLAllCollection rooted at the document node. This is a legacy, non-standard property and should not be used.

Document.applets Read onlyReturns an ordered list of the applets within a document.

Document.bgColor Gets/sets the background color of the current document.

Document.charset Read onlyAlias of 

Document.characterSet. Use this property instead.

Document.domConfig Should return a DOMConfiguration object.

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

Document.fullscreentrue when the document is in full-screen mode.

Document.height  Gets/sets the height of the current document.

Document.inputEncoding Read onlyAlias of 

Document.characterSet. Use this property instead.

Document.linkColor Gets/sets the color of hyperlinks in the document.Document.rootElement Like 

Document.documentElement, but only for <svg> root elements. Use this property instead.Document.vlinkColor Gets/sets the color of visited hyperlinks.

Document.width  Returns the width of the current document.

Document.xmlEncoding Returns the encoding as determined by the XML declaration.

Document.xmlStandalone 

Obsolete since Gecko 10Returns 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 10Returns the version number as specified in the XML declaration or "1.0" if the declaration is absent.

Leave a reply:

Your email address will not be published.

Site Footer

Sliding Sidebar

Facebook