Skip to content

globals/HTMLElement.prototype

Mocks of the lookup, visibility, style and event helpers Obsidian adds to HTMLElement.prototype.

Function Description
find Finds the first descendant matching a selector.
findAll Finds every descendant matching a selector.
findAllSelf Finds every element matching a selector, including the element itself.
hide Hides the element by setting its inline display to none.
isShown Checks whether the element is shown: attached to the DOM with no ancestor hidden by display: none. The mock relies on offsetParent, which jsdom leaves null, so it reports false unless a test defines offsetParent.
off Removes a delegated event listener registered with on. As in Obsidian, every registration whose selector, listener and options are all identical to the ones given is removed.
on Adds a delegated event listener, as Obsidian does: it is called only for events whose target, or an ancestor of it up to this element, matches selector, with that matching element as delegateTarget. The registration is kept in _EVENTS.
onClickEvent Listens for clicks on the element. The mock registers a plain click listener, which cannot be removed.
onNodeInserted Calls a listener when the element is inserted into the DOM. The mock observes nothing: it calls the listener once, immediately.
onWindowMigrated Calls a listener when the element is migrated to another window. The mock never calls it, since tests have a single window.
setCssProps Sets CSS properties, including custom properties such as --size, on the element’s inline style.
setCssStyles Assigns camelCase style declarations to the element’s inline style.
show Shows the element by clearing its inline display.
toggle Shows or hides the element through its inline display.
toggleVisibility Shows or hides the element through its inline visibility, so it keeps its place in the layout.
trigger Dispatches a bubbling, cancelable event of the given type on the element.