Element
Element is the DOM accessor JOPS returns from view.get(id) (and, as an array, from view.find(id)). It wraps one element of the view for reading and writing, with methods that chain and never throw.
You don’t construct it: get it from a view. Since 1.1.8 it is exported for type annotations (import { Element } from "jops-core"); importing it shadows the DOM’s global Element type in that file.
const title = this.get("title"); // ElementLearn more: Elements.
Methods
Section titled “Methods”set(html: string): ElementSets the element’s innerHTML (plain text or HTML).
Returns the same wrapper, for chaining.
this.get("username").set("Alice");this.get("quote_id").set(layout`${quote.number}`);set() replaces plain markup. Don’t use it to clear a container that holds subviews: call removeSubViews() first, otherwise the old views stay in the parent’s subViews.
attr()
Section titled “attr()”attr(name: string, value?: string | number | boolean | null): ElementSets an attribute on the element.
Parameters
name: the attribute name, for example"href".value: the value.nullorundefinedremoves the attribute;""sets a boolean attribute (disabled,hidden,required).
Returns the same wrapper, for chaining.
this.get("quote_id") .set(layout`${quote.number}`) .attr("href", `#quote?id=${quote.id}`);
this.get("save").attr("disabled", ""); // disablethis.get("save").attr("disabled", null); // enable againvalue()
Section titled “value()”value(): stringReturns the element’s current innerHTML, or "" when no element has the id.
const current = this.get("username").value();Properties
Section titled “Properties”element
Section titled “element”element: globalThis.Element | nullThe underlying DOM element, for anything the wrapper doesn’t cover (classList, textContent, form properties). null when no element has that id.
this.get("status").element.classList.add("active");Static methods
Section titled “Static methods”Element.from()
Section titled “Element.from()”Element.from(element: HTMLElement, id: string): ElementWraps an element you already have. This is how view.find(id) builds its results.
Missing elements and destroyed views
Section titled “Missing elements and destroyed views”set(), attr() and value() never throw:
- No element with the id (usually a typo): they do nothing,
value()returns"", and a warning with the id is logged. - The view was destroyed (for example, an async request finished after the user left the screen): they do nothing, silently.
Code that uses element or view.domNode directly has no such guard; check for null yourself.