[]previous and next page

anchor

Creates a text anchor: an empty Text node placed before before (appended when null).

Creates a text anchor: an empty Text node placed before before (appended when null). Use it as the stable insertion point between two dynamic regions; it is never removed by the runtime.

Import#

ts
import { anchor } from "@shadow-js/web";

Signature#

ts
function anchor(parent: Node, before: Node | null): Text

Parameters#

Name Description
parent Node that receives the anchor.
before Node the anchor goes before, or null to append.

Returns#

The new empty Text node.

Examples#

ts
import { anchor, insert } from "@shadow-js/web";

const list = document.createElement("ul");
const slot = anchor(list, null);
insert(list, "first", slot); // goes before the anchor