ElementContext

12 Sep 20259 minutes to read

ElementContext

Properties

CDATA_SECTION_NODE number

node is a CDATASection node.

COMMENT_NODE number

node is a Comment node.

DOCUMENT_FRAGMENT_NODE number

node is a DocumentFragment node.

DOCUMENT_NODE number

node is a document.

DOCUMENT_POSITION_CONTAINED_BY number

Set when other is a descendant of node.

DOCUMENT_POSITION_CONTAINS number

Set when other is an ancestor of node.

DOCUMENT_POSITION_DISCONNECTED number

Set when node and other are not in the same tree.

DOCUMENT_POSITION_FOLLOWING number

Set when other is following node.

DOCUMENT_POSITION_PRECEDING number

Set when other is preceding node.

DOCUMENT_TYPE_NODE number

node is a doctype.

ELEMENT_NODE number

node is an element.

PROCESSING_INSTRUCTION_NODE number

node is a ProcessingInstruction node.

TEXT_NODE number

node is a Text node.

baseURI string

Returns node’s node document’s document base URL.

childNodes NodeListOf

Returns the children.

children HTMLCollection

Returns the child elements.

classList DOMTokenList

Allows for manipulation of element’s class content attribute as a set of whitespace-separated tokens through a DOMTokenList object.

className string

Returns the value of element’s class content attribute. Can be set to change it.

firstChild ChildNode|null

Returns the first child.

firstElementChild Element|null

Returns the first child that is an element, and null otherwise.

id string

Returns the value of element’s id content attribute. Can be set to change it.

isConnected boolean

Returns true if node is connected and false otherwise.

lastChild ChildNode|null

Returns the last child.

lastElementChild Element|null

Returns the last child that is an element, and null otherwise.

localName string

Returns the local name.

namespaceURI string|null

Returns the namespace.

nextElementSibling Element|null

Returns the first following sibling that is an element, and null otherwise.

nextSibling ChildNode|null

Returns the next sibling.

nodeName string

Returns a string appropriate for the type of node.

nodeType number

Returns the type of node.

onabort Object|null

Fires when the user aborts the download.

onblur Object|null

Fires when the object loses the input focus.

oncanplay Object|null

Occurs when playback is possible, but would require further buffering.

onchange Object|null

Fires when the contents of the object or selection have changed.

onclick Object|null

Fires when the user clicks the left mouse button on the object

oncontextmenu Object|null

Fires when the user clicks the right mouse button in the client area, opening the context menu.

ondblclick Object|null

Fires when the user double-clicks the object.

ondrag Object|null

Fires on the source object continuously during a drag operation.

ondragend Object|null

Fires on the source object when the user releases the mouse at the close of a drag operation.

ondragenter Object|null

Fires on the target element when the user drags the object to a valid drop target.

ondragleave Object|null

Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation.

ondragover Object|null

Fires on the target element continuously while the user drags the object over a valid drop target.

ondragstart Object|null

Fires on the source object when the user starts to drag a text selection or selected object.

ondurationchange Object|null

Occurs when the duration attribute is updated.

onemptied Object|null

Occurs when the media element is reset to its initial state.

onended Object|null

Occurs when the end of playback is reached.

onerror OnErrorEventHandler

Fires when an error occurs during object loading.

onfocus Object|null

Fires when the object receives focus.

onkeydown Object|null

Fires when the user presses a key.

onkeypress Object|null

Fires when the user presses an alphanumeric key.

onkeyup Object|null

Fires when the user releases a key.

onload Object|null

Fires immediately after the browser loads the object.

onloadeddata Object|null

Occurs when media data is loaded at the current playback position.

onloadedmetadata Object|null

Occurs when the duration and dimensions of the media have been determined.

onloadstart Object|null

Occurs when Internet Explorer begins looking for media data.

onmousedown Object|null

Fires when the user clicks the object with either mouse button.

onmousemove Object|null

Fires when the user moves the mouse over the object.

onmouseout Object|null

Fires when the user moves the mouse pointer outside the boundaries of the object.

onmouseover Object|null

Fires when the user moves the mouse pointer into the object.

onmouseup Object|null

Fires when the user releases a mouse button while the mouse is over the object.

onpause Object|null

Occurs when playback is paused.

onplay Object|null

Occurs when the play method is requested.

onplaying Object|null

Occurs when the audio or video has started playing.

onprogress Object|null

Occurs to indicate progress while downloading media data.

onratechange Object|null

Occurs when the playback rate is increased or decreased.

onreset Object|null

Fires when the user resets a form.

onscroll Object|null

Fires when the user repositions the scroll box in the scroll bar on the object.

onseeked Object|null

Occurs when the seek operation ends.

onseeking Object|null

Occurs when the current playback position is moved.

onselect Object|null

Fires when the current selection changes.

onstalled Object|null

Occurs when the download has stopped.

onsuspend Object|null

Occurs if the load operation has been intentionally halted.

ontimeupdate Object|null

Occurs to indicate the current playback position.

onvolumechange Object|null

Occurs when the volume is changed, or playback is muted or unmuted.

onwaiting Object|null

Occurs when playback stops because the next frame of a video resource is not available.

ownerDocument Document|null

Returns the node document. Returns null for documents.

parentElement HTMLElement|null

Returns the parent element.

parentNode Node & ParentNode|null

Returns the parent.

prefix string|null

Returns the namespace prefix.

previousElementSibling Element|null

Returns the first preceding sibling that is an element, and null otherwise.

previousSibling Node|null

Returns the previous sibling.

shadowRoot ShadowRoot|null

Returns element’s shadow root, if any, and if shadow root’s mode is “open”, and null otherwise.

slot string

Returns the value of element’s slot content attribute. Can be set to change it.

tagName string

Returns the HTML-uppercased qualified name.

Methods

after

Inserts nodes just after node, while replacing strings in nodes with equivalent Text nodes.
Throws a “HierarchyRequestError” DOMException if the constraints of the node tree are violated.

Returns void

append

Inserts nodes after the last child of node, while replacing strings in nodes with equivalent Text nodes.
Throws a “HierarchyRequestError” DOMException if the constraints of the node tree are violated.

Returns void

attachShadow

Creates a shadow root for element and returns it.

Returns ShadowRoot

before

Inserts nodes just before node, while replacing strings in nodes with equivalent Text nodes.
Throws a “HierarchyRequestError” DOMException if the constraints of the node tree are violated.

Returns void

cloneNode

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

Returns Node

closest

Returns the first (starting at element) inclusive ancestor that matches selectors, and null otherwise.

Returns null

compareDocumentPosition

Returns a bitmask indicating the position of other relative to node.

Returns number

contains

Returns true if other is an inclusive descendant of node, and false otherwise.

Returns boolean

dispatchEvent

Dispatches a synthetic event event to target and returns true if either event’s cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

Returns boolean

getAttribute

Returns element’s first attribute whose qualified name is qualifiedName, and null if there is no such attribute otherwise.

Returns string | null

getAttributeNS

Returns element’s attribute whose namespace is namespace and local name is localName, and null if there is no such attribute otherwise.

Returns string | null

getAttributeNames

Returns the qualified names of all element’s attributes. Can contain duplicates.

Returns string[]

getElementsByClassName

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.

Returns HTMLCollectionOf

getRootNode

Returns node’s root.

Returns Node

hasAttribute

Returns true if element has an attribute whose qualified name is qualifiedName, and false otherwise.

Returns boolean

hasAttributeNS

Returns true if element has an attribute whose namespace is namespace and local name is localName.

Returns boolean

hasAttributes

Returns true if element has attributes, and false otherwise.

Returns boolean

hasChildNodes

Returns whether node has children.

Returns boolean

isEqualNode

Returns whether node and otherNode have the same properties.

Returns boolean

matches

Returns true if matching selectors against element’s root yields element, and false otherwise.

Returns boolean

normalize

Removes empty exclusive Text nodes and concatenates the data of remaining contiguous exclusive Text nodes into the first of their nodes.

Returns void

prepend

Inserts nodes before the first child of node, while replacing strings in nodes with equivalent Text nodes.
Throws a “HierarchyRequestError” DOMException if the constraints of the node tree are violated.

Returns void

querySelector

Returns the first element that is a descendant of node that matches selectors.

Returns null

querySelectorAll

Returns all element descendants of node that match selectors.

Returns NodeListOf

remove

Removes node.

Returns void

removeAttribute

Removes element’s first attribute whose qualified name is qualifiedName.

Returns void

removeAttributeNS

Removes element’s attribute whose namespace is namespace and local name is localName.

Returns void

replaceWith

Replaces node with nodes, while replacing strings in nodes with equivalent Text nodes.
Throws a “HierarchyRequestError” DOMException if the constraints of the node tree are violated.

Returns void

requestFullscreen

Displays element fullscreen and resolves promise when done.
When supplied, options’s navigationUI member indicates whether showing navigation UI while in fullscreen is preferred or not. If set to “show”, navigation simplicity is preferred over screen space, and if set to “hide”, more screen space is preferred. User agents are always free to honor user preference over the application’s. The default value “auto” indicates no application preference.

Returns Promise

setAttribute

Sets the value of element’s first attribute whose qualified name is qualifiedName to value.

Returns void

setAttributeNS

Sets the value of element’s attribute whose namespace is namespace and local name is localName to value.

Returns void

toggleAttribute

If force is not given, “toggles” qualifiedName, removing it if it is present and adding it if it is not present. If force is true, adds qualifiedName. If force is false, removes qualifiedName.
Returns true if qualifiedName is now present, and false otherwise.

Returns boolean