Document.registerElement()

Deprecated
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Warning: document.registerElement() is deprecated in favor of customElements.define().

Draft
This page is not complete.

The document.registerElement() method registers a new custom element in the browser and returns a constructor for the new element.

Note: This is an experimental technology. The browser you use it in must support Web Components. See Enabling Web Components in Firefox.

Syntax

var constructor = document.registerElement(tag-name, options);

Parameters

tag-name
The name of the custom element. The name must contain a dash (-), for example my-tag.
optionsOptional

An object with properties prototype to base the custom element on, and extends, an existing tag to extend. Both of these are optional.

Example

Here is a very simple example:

var Mytag = document.registerElement('my-tag');

Now the new tag is registered in the browser. The Mytag variable holds a constructor that you can use to create a my-tag element in the document as follows:

document.body.appendChild(new Mytag());

This inserts an empty my-tag element that will be visible if you use the browser's developer tools. It will not be visible if you use the browser's view source capability. And it won't be visible in the browser unless you add some content to the tag. Here is one way to add content to the new tag:

var mytag = document.getElementsByTagName("my-tag")[0];
mytag.textContent = "I am a my-tag element.";

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
registerElement
DeprecatedNon-standard
Chrome No support 35 — 80Edge No support 79 — 80Firefox No support 31 — 59
Disabled
No support 31 — 59
Disabled
Disabled From version 31 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.
IE No support NoOpera No support 25 — 67Safari No support NoWebView Android No support 37 — 80Chrome Android No support 35 — 80Firefox Android No support 31 — 59
Disabled
No support 31 — 59
Disabled
Disabled From version 31 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.
Opera Android Full support 25Safari iOS No support NoSamsung Internet Android Full support 3.0

Legend

Full support
Full support
No support
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also