DOM Methods
CustomElementRegistry.upgrade()
Attempts to upgrade eligible custom elements in a subtree, including disconnected elements. Definitions must already exist in the registry. This does not connect the subtree or fire connectedCallback just by upgrading it. Example result: true.
Formal Syntax & Structure
html syntaxhtml
customElements.upgrade(root)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| root | Node | Root of subtree to upgrade. |
Return Value
undefined
No return value.
Working Example
Example Snippethtml
<p> Result: <output id="result"></output></p><script> const result = document.getElementById("result"); (async () => { const fragment = document.createDocumentFragment(); const el = document.createElement("demo-card"); fragment.append(el); class DemoCard extends HTMLElement {} customElements.define("demo-card", DemoCard); customElements.upgrade(fragment); result.textContent = el instanceof DemoCard; })().catch(error => { result.textContent = "Error: " + error.name; });</script>