Skip to content

element.on()

Method@tryyoursize/sdk

Listens to an element event. A handler that throws never breaks the SDK or the other handlers.

on<K extends keyof ElementEvents>(event: K, handler: (e: ElementEvents[K]) => void): void;
eventkeyof ElementEventsRequired

"ready", "size", "open", "close", "loaderror" or "recommendation". See the event pages.

handler(e: ElementEvents[K]) => voidRequired

Called with the event payload.

guide.on("recommendation", (r) => r.status === "ready" && preselect(r.size));
guide.on("size", ({ size }) => preselect(size)); // "Use this size" in the window
guide.on("loaderror", ({ error }) => console.warn(error.code));

Was this page helpful?