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 compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

661

542

No3

594

Yes — 595

No

531

412

10.16
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support

661

542

661

542

No3

594

Yes — 595

531

412

10.166.02

1. Support for 'Customized built-in elements' as well.

2. Support for 'Autonomous custom elements' only.

3. Under consideration

4. 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.

5. 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.

6. Supports 'Autonomous custom elements' but not 'Customized built-in elements'

Document Tags and Contributors

 Contributors to this page: jpmedley, fscholz, chrisdavidmills, snuggs, arthurevans
 Last updated by: jpmedley,