CustomElementRegistry.upgrade()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

We'd love to hear more about your role and the company you work for
Please help us by answering a few questions.

upgrade()CustomElementRegistry インターフェイスのメソッドで、 Node サブツリー内のすべてのシャドウを含むカスタム要素を、メイン文書に接続する前であってもアップグレードします。

構文

js
customElements.upgrade(root);

引数

root

アップグレードされる、シャドウを含む子孫要素を持つ Node インスタンス。アップグレード可能な子孫要素がない場合、エラーは発生しません。

返値

なし。

HTML 仕様書 から取りました。

js
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
HTML
# dom-customelementregistry-upgrade-dev

ブラウザーの互換性