🔸custom element

browserweb componentsimplement ⟩ custom elements

circle-check
triangle-exclamation
circle-check
// define new custom element
customElements.define(
  'web-component',                    // ⭐️ HTML tag name, must have "-"❗️ 
  class extends HTMLElement { ... }   // ⭐️ must extend `HTMLElement`❗️ 
);
circle-exclamation

Valid Custom Element Name

circle-info
  • 開頭:[a-z] ⭐️

  • 接著:[0-9], [a-z], "-", ".", "_" (optional)

  • 中間一定要有:"-" ⭐️

  • 接著:[0-9], [a-z], "-", ".", "_" (optional)

circle-info

<vstack-> 或 <i-vstack> ❓(這兩個都是合法的名字)

Register New Tag Name

We can create our tags by using the CustomElementRegistryarrow-up-right object (window.customElements).

triangle-exclamation

Supporting Class

To create a custom element, we need to tell the browser several details about it: how to show it, what to do when the element is added or removed to page, etc.

Last updated

Was this helpful?