Skip to content

globals/Element.prototype

Mocks of the class, attribute, text and lookup helpers Obsidian adds to Element.prototype.

Function Description
addClass Adds one or more CSS classes to the element.
addClasses Adds a list of CSS classes to the element.
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.
getAttr Reads an attribute, like getAttribute.
getCssPropertyValue Reads a CSS property from the element’s computed style.
getText Reads the element’s text.
hasClass Checks whether the element has a CSS class.
isActiveElement Checks whether the element has focus. The mock compares against the global document.activeElement, so an element in a pop-out document never counts as active.
matchParent Finds the nearest element matching a selector, as Obsidian does: the element itself is checked first, then each ancestor in turn.
removeClass Removes one or more CSS classes from the element.
removeClasses Removes a list of CSS classes from the element.
setAttr Sets an attribute, or removes it when the value is null.
setAttrs Sets several attributes at once, as setAttr does for each entry.
setText Replaces the element’s children with text or a fragment.
toggleClass Adds or removes CSS classes depending on a flag.