--- title: Document.registerElement() slug: Web/API/Document/registerElement translation_of: Web/API/Document/registerElement ---
{{APIRef("DOM")}}
{{draft()}}
Метод Document.registerElement()
регистрирует новый кастомный элемент (custom element) в браузере и возвращает конструктор для этого нового элемента.
Примечание: Это экспериментальная технология . Браузер который вы используете должен поддерживать Веб Компоненты (Web Components). Смотри больше: Enabling Web Components in Firefox.
var constructor = document.registerElement(tag-name, options);
my-tag
.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.";
Specification | Status | Comment |
---|---|---|
{{SpecName('Custom Elements')}} | {{Spec2('Custom Elements')}} | Initial definition |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 35 | 31 (behind a flag) | {{CompatNo}} | 25 | {{CompatNo}} |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 4.4.4 | 31 (behind a flag) | {{CompatNo}} | 25 | {{CompatNo}} |