[]previous and next page

delegateEvents

Installs the document listener that runs delegated handlers for each event name, once per document and name; repeated calls do nothing.

Installs the document listener that runs delegated handlers for each event name, once per document and name; repeated calls do nothing. Compiled modules call it for the events they delegate, so application code rarely needs it. The listener walks composedPath() from the target outward and runs each element's delegated handler in one batch, stopping when a handler stops propagation. A non-composed event raised inside a shadow root never reaches the document, so bind such events natively.

Import#

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

Signature#

ts
function delegateEvents(names: string[], target: Document = globalThis.document): void

Parameters#

Name Description
names Event names to delegate, such as ["click", "input"].
target Document that receives the listeners. Default: the global document.

Examples#

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

delegateEvents(["click", "input"]);