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
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'customElements.get()' in that specification. |
Living Standard | Initial definition. |
Browser compatibility
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.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
get | Chrome
Full support
66
| Edge
Full support
79
| Firefox
Full support
63
| IE No support No | Opera
Full support
53
| Safari
Full support
10.1
| WebView Android
Full support
66
| Chrome Android
Full support
66
| Firefox Android
Full support
63
| Opera Android
Full support
47
| Safari iOS
Full support
10.3
| Samsung Internet Android
Full support
9.0
|
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.