Pier Pier - 6 months ago 10
HTML Question

Is it mandatory to use document.registerElement()?

I'm using custom HTML tags such as

<custom-element>
for semantic convenience and styling those using CSS. I'm also using the tag name as a selector for jQuery such as
$('custom-element')
.

I've removed
document.registerElement('custom-element')
from my code, and everything works as expected in Chrome.

Is it mandatory to use
document.registerElement('custom-element')
even if I'm not using any Javascript with those custom elements (except for the jQuery selector)?

Answer

The only thing registerElement does is allow you to create objects of the new element programmatically via constructor as opposed to by using createElement. This enables you to also add a prototype to the element, or extend an existing element, which AFAIK you can't do with createElement. You don't need to register custom elements if you don't need one of these three things (a constructor, the extension of an existing element, a prototype).

Comments