dom
DOM utility functions
walkDOM
Walk the DOM tree and collect all elements with data-volt-* attributes in document order (parent before children).
Skips children of elements with data-volt-for or data-volt-if since those will be processed when the parent element is cloned and mounted.
export function walkDOM(root: Element): Element[]hasVoltAttribute
Check if an element has any data-volt-* attributes.
export function hasVoltAttribute(element: Element): booleangetVoltAttributes
Get all data-volt-* attributes from an element. Excludes charge metadata attributes (state, computed:*) that are processed separately.
export function getVoltAttributes(element: Element): Map<string, string>setText
Set the text content of an element safely.
export function setText(element: Element, value: unknown): voidsetHTML
Set the HTML content of an element safely. Note: This trusts the input HTML and should only be used with sanitized content.
export function setHTML(element: Element, value: string): voidtoggleClass
Add or remove a CSS class from an element.
export function toggleClass(element: Element, className: string, add: boolean): voidparseClassBinding
Parse a class binding expression. Supports string values ("active"), object notation ({active: true}), and other primitives (true, false, numbers) which are converted to strings.
export function parseClassBinding(value: unknown): Map<string, boolean>