Document.registerElement()

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

* Some parts of this feature may have varying levels of support.

Метод Document.registerElement() регистрирует новый кастомный элемент (custom element) в браузере и возвращает конструктор для этого нового элемента.

Примечание: Это экспериментальная технология. Браузер который вы используете должен поддерживать Веб Компоненты (Web Components). Смотри больше: Enabling Web Components in Firefox.

Примечание: Устарело. Используйте интерфейс CustomElementRegistry и его метод define(), чтобы зарегистрировать новый Тег.

Syntax

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

Parameters

tag-name

Имя кастомного элемента. Имя должно содержать символ дефиса (-), например: my-tag.

options Необязательный

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

Example

Here is a very simple example:

js
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:

js
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:

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

Спецификации

Specification
HTML
# dom-customelementregistry-define-dev

Совместимость с браузерами

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
define
Supports disabledFeatures static property

Legend

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

Full support
Full support
No support
No support

Смотрите также