--- title: CustomElementRegistry.upgrade() slug: Web/API/CustomElementRegistry/upgrade translation_of: Web/API/CustomElementRegistry/upgrade ---
{{APIRef("CustomElementRegistry")}}
CustomElementRegistry接口的upgrade()方法将更新节点子树中所有包含阴影的自定义元素,甚至在它们连接到主文档之前也是如此。
customElements.upgrade(root);
root节点 。如果没有可升级的派生实例,则不会抛出异常。空.
摘至HTML 规范:
const el = document.createElement("spider-man");
class SpiderMan extends HTMLElement {}
customElements.define("spider-man", SpiderMan);
console.assert(!(el instanceof SpiderMan)); // not yet upgraded
customElements.upgrade(el);
console.assert(el instanceof SpiderMan); // upgraded!
| Specification | Status | Comment |
|---|---|---|
| {{SpecName("HTML WHATWG", "custom-elements.html#dom-customelementregistry-upgrade", "customElements.upgrade()")}} | {{Spec2("HTML WHATWG")}} | Initial definition. |
{{Compat("api.CustomElementRegistry.upgrade")}}