CustomElementRegistry: getName() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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

Syntax

js
getName(constructor)

Parameters

constructor

Constructor for the custom element.

Return value

The name for the previously defined custom element, or null if there is no custom element defined with the constructor.

Examples

js
class MyParagraph extends HTMLElement {
  constructor() {
    const template = document.getElementById("custom-paragraph");
    super() // returns element this scope
      .attachShadow({ mode: "open" }) // sets AND returns this.shadowRoot
      .append(document.importNode(template.content, true));
  }
}

customElements.define("my-paragraph", MyParagraph);

// Return a reference to the my-paragraph constructor
customElements.getName(MyParagraph) === "my-paragraph";

Specifications

Specification
HTML
# dom-customelementregistry-getname

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
getName
Chrome – Full support
Chrome 117 (Release date: 2023-09-12)
footnote Full support
Edge – Full support
Edge 117 (Release date: 2023-09-15)
footnote Full support
Firefox – Full support
Firefox 116 (Release date: 2023-08-01)
footnote Full support
Opera – Full support
Opera 103 (Release date: 2023-10-03)
footnote Full support
Safari – Partial support
Safari 17 (Release date: 2023-09-18)
footnote Partial support
footnote Supports 'Autonomous custom elements' but not 'Customized built-in elements'.
Chrome Android – Full support
Chrome Android 117 (Release date: 2023-09-12)
footnote Full support
Firefox for Android – Full support
Firefox for Android 116 (Release date: 2023-08-01)
footnote Full support
Opera Android – Full support
Opera Android 78 (Release date: 2023-10-23)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 17 (Release date: 2023-09-18)
footnote Partial support
footnote Supports 'Autonomous custom elements' but not 'Customized built-in elements'.
Samsung Internet – Full support
Samsung Internet 24 (Release date: 2024-01-25)
footnote Full support
WebView Android – Full support
WebView Android 117 (Release date: 2023-09-12)
footnote Full support
WebView on iOS – Partial support
WebView on iOS 17 (Release date: 2023-09-18)
footnote Partial support
footnote Supports 'Autonomous custom elements' but not 'Customized built-in elements'.

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support