Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/evt/lib/index.ts>dom.Document

💧EventEmitter's typesafe replacement
Go to Latest
import { type dom } from "https://deno.land/x/evt@v2.4.22/lib/index.ts";
const { Document } = dom;

Any web page loaded in the browser and serves as an entry point into the web page's content, which is the DOM tree.

Properties

readonly
URL: string

Sets or gets the URL for the current document.

deprecated
alinkColor: string
readonly
deprecated
all: HTMLAllCollection
readonly
deprecated
anchors: HTMLCollectionOf<HTMLAnchorElement>
readonly
deprecated
applets: HTMLCollectionOf<HTMLAppletElement>
deprecated
bgColor: string

Specifies the beginning and end of the document body.

readonly
characterSet: string

Returns document's encoding.

readonly
charset: string

Gets or sets the character set used to encode the object.

readonly
compatMode: string

Gets a value that indicates whether standards-compliant mode is switched on for the object.

readonly
contentType: string

Returns document's content type.

readonly
currentScript: HTMLOrSVGScriptElement | null

Returns the script element, or the SVG script element, that is currently executing, as long as the element represents a classic script. In the case of reentrant script execution, returns the one that most recently started executing amongst those that have not yet finished executing.

Returns null if the Document is not currently executing a script or SVG script element (e.g., because the running script is an event handler, or a timeout), or if the currently executing script or SVG script element represents a module script.

readonly
defaultView: WindowProxy | null
designMode: string

Sets or gets a value that indicates whether the document can be edited.

dir: string

Sets or retrieves a value that indicates the reading order of the object.

readonly
doctype: DocumentType | null

Gets an object representing the document type declaration associated with the current document.

readonly
documentElement: HTMLElement

Gets a reference to the root node of the document.

readonly
documentURI: string

Returns document's URL.

domain: string

Sets or gets the security domain of the document.

Retrieves a collection of all embed objects in the document.

deprecated
fgColor: string

Retrieves a collection, in source order, of all form objects in the document.

readonly
deprecated
fullscreen: boolean
readonly
fullscreenEnabled: boolean

Returns true if document has the ability to display elements fullscreen and fullscreen is supported, or false otherwise.

readonly
head: HTMLHeadElement

Returns the head element.

readonly
hidden: boolean

Retrieves a collection, in source order, of img objects in the document.

readonly
implementation: DOMImplementation

Gets the implementation object of the current document.

readonly
inputEncoding: string

Returns the character encoding used to create the webpage that is loaded into the document object.

readonly
lastModified: string

Gets the date that the page was last modified, if the page supplies one.

deprecated
linkColor: string
location: Location

Contains information about the current URL.

onfullscreenchange: ((this: Document, ev: Event) => any) | null
onfullscreenerror: ((this: Document, ev: Event) => any) | null
onpointerlockchange: ((this: Document, ev: Event) => any) | null
onpointerlockerror: ((this: Document, ev: Event) => any) | null
onreadystatechange: ((this: Document, ev: Event) => any) | null

Fires when the state of the object has changed.

onvisibilitychange: ((this: Document, ev: Event) => any) | null
readonly
origin: string

Returns document's origin.

Return an HTMLCollection of the embed elements in the Document.

readonly
readyState: DocumentReadyState

Retrieves a value that indicates the current state of the object.

readonly
referrer: string

Gets the URL of the location that referred the user to the current page.

Retrieves a collection of all script objects in the document.

readonly
scrollingElement: Element | null
readonly
timeline: DocumentTimeline
title: string

Contains the title of the document.

readonly
visibilityState: VisibilityState
deprecated
vlinkColor: string

Methods

adoptNode<T extends Node>(source: T): T

Moves node from another document and returns it.

If node is a document, throws a "NotSupportedError" DOMException or, if node is a shadow root, throws a "HierarchyRequestError" DOMException.

deprecated
captureEvents(): void
caretPositionFromPoint(x: number, y: number): CaretPosition | null
deprecated
caretRangeFromPoint(x: number, y: number): Range
deprecated
clear(): void
close(): void

Closes an output stream and forces the sent data to display.

createAttribute(localName: string): Attr

Creates an attribute object with a specified name.

createAttributeNS(namespace: string | null, qualifiedName: string): Attr
createCDATASection(data: string): CDATASection

Returns a CDATASection node whose data is data.

createComment(data: string): Comment

Creates a comment object with the specified data.

createDocumentFragment(): DocumentFragment

Creates a new document.

createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K]

Creates an instance of the element for the specified tag.

deprecated
createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementDeprecatedTagNameMap[K]
createElement(tagName: string, options?: ElementCreationOptions): HTMLElement
createElementNS(namespaceURI: "http://www.w3.org/1999/xhtml", qualifiedName: string): HTMLElement

Returns an element with namespace namespace. Its namespace prefix will be everything before ":" (U+003E) in qualifiedName or null. Its local name will be everything after ":" (U+003E) in qualifiedName or qualifiedName.

If localName does not match the Name production an "InvalidCharacterError" DOMException will be thrown.

If one of the following conditions is true a "NamespaceError" DOMException will be thrown:

localName does not match the QName production. Namespace prefix is not null and namespace is the empty string. Namespace prefix is "xml" and namespace is not the XML namespace. qualifiedName or namespace prefix is "xmlns" and namespace is not the XMLNS namespace. namespace is the XMLNS namespace and neither qualifiedName nor namespace prefix is "xmlns".

When supplied, options's is can be used to create a customized built-in element.

createElementNS<K extends keyof SVGElementTagNameMap>(namespaceURI: "http://www.w3.org/2000/svg", qualifiedName: K): SVGElementTagNameMap[K]
createElementNS(namespaceURI: "http://www.w3.org/2000/svg", qualifiedName: string): SVGElement
createElementNS(
namespaceURI: string | null,
qualifiedName: string,
): Element
createElementNS(
namespace: string | null,
qualifiedName: string,
options?: string | ElementCreationOptions,
): Element
createEvent(eventInterface: "AnimationEvent"): AnimationEvent
createEvent(eventInterface: "AnimationPlaybackEvent"): AnimationPlaybackEvent
createEvent(eventInterface: "AudioProcessingEvent"): AudioProcessingEvent
createEvent(eventInterface: "BeforeUnloadEvent"): BeforeUnloadEvent
createEvent(eventInterface: "ClipboardEvent"): ClipboardEvent
createEvent(eventInterface: "CloseEvent"): CloseEvent
createEvent(eventInterface: "CompositionEvent"): CompositionEvent
createEvent(eventInterface: "CustomEvent"): CustomEvent
createEvent(eventInterface: "DeviceLightEvent"): DeviceLightEvent
createEvent(eventInterface: "DeviceMotionEvent"): DeviceMotionEvent
createEvent(eventInterface: "DeviceOrientationEvent"): DeviceOrientationEvent
createEvent(eventInterface: "DragEvent"): DragEvent
createEvent(eventInterface: "ErrorEvent"): ErrorEvent
createEvent(eventInterface: "Event"): Event
createEvent(eventInterface: "Events"): Event
createEvent(eventInterface: "FocusEvent"): FocusEvent
createEvent(eventInterface: "FocusNavigationEvent"): FocusNavigationEvent
createEvent(eventInterface: "GamepadEvent"): GamepadEvent
createEvent(eventInterface: "HashChangeEvent"): HashChangeEvent
createEvent(eventInterface: "IDBVersionChangeEvent"): IDBVersionChangeEvent
createEvent(eventInterface: "InputEvent"): InputEvent
createEvent(eventInterface: "KeyboardEvent"): KeyboardEvent
createEvent(eventInterface: "ListeningStateChangedEvent"): ListeningStateChangedEvent
createEvent(eventInterface: "MSGestureEvent"): MSGestureEvent
createEvent(eventInterface: "MSMediaKeyMessageEvent"): MSMediaKeyMessageEvent
createEvent(eventInterface: "MSMediaKeyNeededEvent"): MSMediaKeyNeededEvent
createEvent(eventInterface: "MSPointerEvent"): MSPointerEvent
createEvent(eventInterface: "MediaEncryptedEvent"): MediaEncryptedEvent
createEvent(eventInterface: "MediaKeyMessageEvent"): MediaKeyMessageEvent
createEvent(eventInterface: "MediaQueryListEvent"): MediaQueryListEvent
createEvent(eventInterface: "MediaStreamErrorEvent"): MediaStreamErrorEvent
createEvent(eventInterface: "MediaStreamEvent"): MediaStreamEvent
createEvent(eventInterface: "MediaStreamTrackEvent"): MediaStreamTrackEvent
createEvent(eventInterface: "MessageEvent"): MessageEvent
createEvent(eventInterface: "MouseEvent"): MouseEvent
createEvent(eventInterface: "MouseEvents"): MouseEvent
createEvent(eventInterface: "MutationEvent"): MutationEvent
createEvent(eventInterface: "MutationEvents"): MutationEvent
createEvent(eventInterface: "OfflineAudioCompletionEvent"): OfflineAudioCompletionEvent
createEvent(eventInterface: "OverflowEvent"): OverflowEvent
createEvent(eventInterface: "PageTransitionEvent"): PageTransitionEvent
createEvent(eventInterface: "PaymentRequestUpdateEvent"): PaymentRequestUpdateEvent
createEvent(eventInterface: "PermissionRequestedEvent"): PermissionRequestedEvent
createEvent(eventInterface: "PointerEvent"): PointerEvent
createEvent(eventInterface: "PopStateEvent"): PopStateEvent
createEvent(eventInterface: "ProgressEvent"): ProgressEvent
createEvent(eventInterface: "PromiseRejectionEvent"): PromiseRejectionEvent
createEvent(eventInterface: "RTCDTMFToneChangeEvent"): RTCDTMFToneChangeEvent
createEvent(eventInterface: "RTCDataChannelEvent"): RTCDataChannelEvent
createEvent(eventInterface: "RTCDtlsTransportStateChangedEvent"): RTCDtlsTransportStateChangedEvent
createEvent(eventInterface: "RTCErrorEvent"): RTCErrorEvent
createEvent(eventInterface: "RTCIceCandidatePairChangedEvent"): RTCIceCandidatePairChangedEvent
createEvent(eventInterface: "RTCIceGathererEvent"): RTCIceGathererEvent
createEvent(eventInterface: "RTCIceTransportStateChangedEvent"): RTCIceTransportStateChangedEvent
createEvent(eventInterface: "RTCPeerConnectionIceErrorEvent"): RTCPeerConnectionIceErrorEvent
createEvent(eventInterface: "RTCPeerConnectionIceEvent"): RTCPeerConnectionIceEvent
createEvent(eventInterface: "RTCSsrcConflictEvent"): RTCSsrcConflictEvent
createEvent(eventInterface: "RTCStatsEvent"): RTCStatsEvent
createEvent(eventInterface: "RTCTrackEvent"): RTCTrackEvent
createEvent(eventInterface: "SVGZoomEvent"): SVGZoomEvent
createEvent(eventInterface: "SVGZoomEvents"): SVGZoomEvent
createEvent(eventInterface: "SecurityPolicyViolationEvent"): SecurityPolicyViolationEvent
createEvent(eventInterface: "ServiceWorkerMessageEvent"): ServiceWorkerMessageEvent
createEvent(eventInterface: "SpeechRecognitionEvent"): SpeechRecognitionEvent
createEvent(eventInterface: "SpeechSynthesisErrorEvent"): SpeechSynthesisErrorEvent
createEvent(eventInterface: "SpeechSynthesisEvent"): SpeechSynthesisEvent
createEvent(eventInterface: "StorageEvent"): StorageEvent
createEvent(eventInterface: "TextEvent"): TextEvent
createEvent(eventInterface: "TouchEvent"): TouchEvent
createEvent(eventInterface: "TrackEvent"): TrackEvent
createEvent(eventInterface: "TransitionEvent"): TransitionEvent
createEvent(eventInterface: "UIEvent"): UIEvent
createEvent(eventInterface: "UIEvents"): UIEvent
createEvent(eventInterface: "VRDisplayEvent"): VRDisplayEvent
createEvent(eventInterface: "VRDisplayEvent "): VRDisplayEvent
createEvent(eventInterface: "WebGLContextEvent"): WebGLContextEvent
createEvent(eventInterface: "WheelEvent"): WheelEvent
createEvent(eventInterface: string): Event
createNodeIterator(
root: Node,
whatToShow?: number,
filter?: NodeFilter | null,
): NodeIterator

Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.

createProcessingInstruction(target: string, data: string): ProcessingInstruction

Returns a ProcessingInstruction node whose target is target and data is data. If target does not match the Name production an "InvalidCharacterError" DOMException will be thrown. If data contains "?>" an "InvalidCharacterError" DOMException will be thrown.

createRange(): Range

Returns an empty range object that has both of its boundary points positioned at the beginning of the document.

createTextNode(data: string): Text

Creates a text string from the specified value.

createTreeWalker(
root: Node,
whatToShow?: number,
filter?: NodeFilter | null,
): TreeWalker

Creates a TreeWalker object that you can use to traverse filtered lists of nodes or elements in a document.

deprecated
createTreeWalker(
root: Node,
whatToShow: number,
filter: NodeFilter | null,
entityReferenceExpansion?: boolean,
): TreeWalker
elementFromPoint(x: number, y: number): Element | null

Returns the element for the specified x coordinate and the specified y coordinate.

elementsFromPoint(x: number, y: number): Element[]
execCommand(
commandId: string,
showUI?: boolean,
value?: string,
): boolean

Executes a command on the current document, current selection, or the given range.

exitFullscreen(): Promise<void>

Stops document's fullscreen element from being displayed fullscreen and resolves promise when done.

exitPointerLock(): void
getAnimations(): Animation[]
getElementById(elementId: string): HTMLElement | null

Returns a reference to the first object with the specified value of the ID or NAME attribute.

getElementsByClassName(classNames: string): HTMLCollectionOf<Element>

Returns a HTMLCollection of the elements in the object on which the method was invoked (a document or an element) that have all the classes given by classNames. The classNames argument is interpreted as a space-separated list of classes.

getElementsByName(elementName: string): NodeListOf<HTMLElement>

Gets a collection of objects based on the value of the NAME or ID attribute.

getElementsByTagName<K extends keyof HTMLElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<HTMLElementTagNameMap[K]>

Retrieves a collection of objects based on the specified element name.

getElementsByTagName<K extends keyof SVGElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<SVGElementTagNameMap[K]>
getElementsByTagName(qualifiedName: string): HTMLCollectionOf<Element>
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf<HTMLElement>

If namespace and localName are "*" returns a HTMLCollection of all descendant elements.

If only namespace is "*" returns a HTMLCollection of all descendant elements whose local name is localName.

If only localName is "*" returns a HTMLCollection of all descendant elements whose namespace is namespace.

Otherwise, returns a HTMLCollection of all descendant elements whose namespace is namespace and local name is localName.

getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf<SVGElement>
getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollectionOf<Element>
getSelection(): Selection | null

Returns an object representing the current selection of the document that is loaded into the object displaying a webpage.

hasFocus(): boolean

Gets a value indicating whether the object currently has focus.

importNode<T extends Node>(importedNode: T, deep: boolean): T

Returns a copy of node. If deep is true, the copy also includes the node's descendants.

If node is a document or a shadow root, throws a "NotSupportedError" DOMException.

open(
url?: string,
name?: string,
features?: string,
replace?: boolean,
): Document

Opens a new window and loads a document specified by a given URL. Also, opens a new window that uses the url parameter and the name parameter to collect the output of the write method and the writeln method.

queryCommandEnabled(commandId: string): boolean

Returns a Boolean value that indicates whether a specified command can be successfully executed using execCommand, given the current state of the document.

queryCommandIndeterm(commandId: string): boolean

Returns a Boolean value that indicates whether the specified command is in the indeterminate state.

queryCommandState(commandId: string): boolean

Returns a Boolean value that indicates the current state of the command.

queryCommandSupported(commandId: string): boolean

Returns a Boolean value that indicates whether the current command is supported on the current range.

queryCommandValue(commandId: string): string

Returns the current value of the document, range, or current selection for the given command.

deprecated
releaseEvents(): void
write(...text: string[]): void

Writes one or more HTML expressions to a document in the specified window.

writeln(...text: string[]): void

Writes one or more HTML expressions, followed by a carriage return, to a document in the specified window.

addEventListener<K extends keyof DocumentEventMap>(
type: K,
listener: (this: Document, ev: DocumentEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void
addEventListener(
type: string,
options?: boolean | AddEventListenerOptions,
): void
removeEventListener<K extends keyof DocumentEventMap>(
type: K,
listener: (this: Document, ev: DocumentEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void
removeEventListener(
type: string,
options?: boolean | EventListenerOptions,
): void