CustomElementRegistry.get()
get()
は CustomElementRegistry
インターフェイスのメソッドで、以前定義したカスタム要素のコンストラクターを返します。
構文
js
constructor = customElements.get(name);
引数
- name
-
コンストラクターの参照を返したいカスタム要素の名前です。
返値
名前付きのカスタム要素のコンストラクター、またはその名前のカスタム要素がない場合は undefined
です。
例
js
customElements.define(
"my-paragraph",
class extends HTMLElement {
constructor() {
let templateContent = document.getElementById("my-paragraph").content;
super() // このスコープの要素を返す
.attachShadow({ mode: "open" }) // this.shadowRoot を設定して返す
.append(templateContent.cloneNode(true));
}
},
);
// my-paragraph のコンストラクターの参照を返す
let ctor = customElements.get("my-paragraph");
仕様書
Specification |
---|
HTML # dom-customelementregistry-get-dev |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
get |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.