このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

CustomElementRegistry: get() メソッド

利用可能性は限定的

この機能はベースラインではありません。最も広く使用されているブラウザーの一部で動作しません。

get()CustomElementRegistry インターフェイスのメソッドで、以前定義したカスタム要素のコンストラクターを返します。

構文

js
get(name)

引数

name

カスタム要素の名前です。

返値

名前付きのカスタム要素のコンストラクター、またはその名前のカスタム要素がない場合は undefined です。

js
customElements.define(
  "my-paragraph",
  class extends HTMLElement {
    constructor() {
      const template = document.getElementById("custom-paragraph");
      super() // このスコープの要素を返す
        .attachShadow({ mode: "open" }) // this.shadowRoot を設定して返す
        .append(document.importNode(template.content, true));
    }
  },
);

// my-paragraph のコンストラクターの参照を返す
const ctor = customElements.get("my-paragraph");

仕様書

仕様書
HTML
# dom-customelementregistry-get-dev

ブラウザーの互換性