W3cubDocs

/DOM

CustomElementRegistry.get

The get() method of the CustomElementRegistry interface returns the constructor for a previously-defined custom element.

Syntax

constructor = customElements.get(name);

Parameters

name
The name of the custom element whose constructor you want to return a reference to.

Return value

The constructor for the named custom element, or undefined if there is no custom element definition with that name.

Examples

customElements.define('my-paragraph',
  class extends HTMLElement {
    constructor() {
      super();
      let template = document.getElementById('my-paragraph');
      let templateContent = template.content;

      const shadowRoot = this.attachShadow({mode: 'open'})
        .appendChild(templateContent.cloneNode(true));
  }
})

// Return a reference to the my-paragraph constructor
let ctor = customElements.get('my-paragraph');

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'customElements.get()' in that specification.
Living Standard Initial definition.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 66
66
Support for 'Customized built-in elements' as well.
54
Support for 'Autonomous custom elements' only.
No
No
Under consideration
63
63
59
Disabled
Disabled From version 59: this feature is behind the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
? — 59
Disabled
Disabled Until version 59 (exclusive): this feature is behind the dom.webcomponents.enabled preference (needs to be set to true) and the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No 53
53
Support for 'Customized built-in elements' as well.
41
Support for 'Autonomous custom elements' only.
10.1
10.1
Supports 'Autonomous custom elements' but not 'Customized built-in elements'
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 66
66
Support for 'Customized built-in elements' as well.
54
Support for 'Autonomous custom elements' only.
66
66
Support for 'Customized built-in elements' as well.
54
Support for 'Autonomous custom elements' only.
No
No
Under consideration
63
63
59
Disabled
Disabled From version 59: this feature is behind the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
? — 59
Disabled
Disabled Until version 59 (exclusive): this feature is behind the dom.webcomponents.enabled preference (needs to be set to true) and the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
53
53
Support for 'Customized built-in elements' as well.
41
Support for 'Autonomous custom elements' only.
10.1
10.1
Supports 'Autonomous custom elements' but not 'Customized built-in elements'
6.0
6.0
Support for 'Autonomous custom elements' only.

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/get