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