Web APIs

CustomElementRegistry.prototype.whenDefined()

Try the free JavaScript compiler

Resolves to the registered constructor once the valid name is defined.

Formal Syntax & Structure

javascript syntaxjavascript
customElements.whenDefined(name)

Parameters & Attributes

NameTypeDescription
namestringValid custom element name.

Return Value

Promise<CustomElementConstructor>

Resolves to the registered constructor once the valid name is defined.

Working Example

Example Snippetjavascript
(async () => {const waiting=customElements.whenDefined("lesson-chip");class LessonChip extends HTMLElement{};customElements.define("lesson-chip",LessonChip);console.log((await waiting)===customElements.get("lesson-chip"));})()
JavaScript Reference