Skip to content

html-element

Obsidian-runtime-agnostic helpers for working with HTML elements.

Several helpers here mirror behavior that the Obsidian runtime injects onto the DOM prototypes (createEl/createDiv/createSpan/createSvg/createFragment, Node.prototype.instanceOf, Element.prototype.setText/setAttrs). To stay independent of the Obsidian runtime, that behavior is reimplemented here in standard DOM, ported from Obsidian’s own implementation in obsidian.asar/enhance.js. See the obsidian-versions project; revalidate the port when Obsidian changes enhance.js (there is a reminder in CLAUDE.md).

InterfaceDescription
ValidatorElementA HTML element that can be validated.
FunctionDescription
createDivAsyncCreates a div asynchronously.
createElAsyncCreates an element asynchronously.
createFragmentAsyncCreates a DocumentFragment asynchronously.
createSpanAsyncCreates a span asynchronously.
createSvgAsyncCreates a svg asynchronously.
ensureLoadedEnsures that the given element is loaded.
getDocumentWindowGets the window a document belongs to. A document is the one node whose ownerDocument is null, so the ownerDocument-chasing lookup used for ordinary nodes resolves a document to the wrong window. Reading defaultView off the document itself is what keeps a pop-out window’s coordinates measured against that window.
getZIndexGets the z-index of the given element.
isElementVisibleInOffsetParentChecks if the element is visible in the offset parent.
isLoadedChecks if the element is loaded.
onAncestorScrollOrResizeAdds an event listener to the ancestor nodes of the given node.
toPxConverts a number to a string with ‘px’ appended.
waitUntilConnectedWaits until the given element is connected to the DOM.