.before(...siblings)
Available on: InDom, InDomArray

Inserts one or more HTML strings, DOM elements or InDom objects before the underlying element(s).

Parameters:
...siblings {(string | Node | InDom)[]} - Content to append (variadic; single array is flattened)

Returns: {InDom | InDomArray} - this for chaining

Throws:
Error - If the underlying element(s) has been removed

Note:
If an argument is a string, it’s parsed as HTML and inserted. Sanitize untrusted strings before passing them.

Examples:
// before examples (mirror of after examples)
const ul = $1('ul.example-1');
const firstLi = $1(">li", ul);

firstLi.before('<div>test</div>'); // raw HTML string
firstLi.before(img); // native DOM element
firstLi.before($n(img)); // same img, in InDom object
firstLi.before($a('>div', donor)); // InDomArray (moves both divs)
$a('>li', ul).before('<span>test</span>'); // bulk before to every <li> of ul
Modern DOM Power
for TypeScript, ESM & Plain JS
3.8KB JavaScript library that simplifies DOM manipulation
with a clean, chainable API for events, data, inputs harvesting, and more.
Automatic Cleanup,
Leak-Proof by Design
Events and state are cleared when elements leave the DOM,
even if removal happens outside InDom.
Cleaner Code,
Better Ergonomics
Get the InDom object directly in callbacks.
One element, one instance.
Works With Your Existing Stack
Use InDom on its own or alongside any library or framework,
its architecture ensures a seamless integration.