Skip to content

Latest commit

 

History

History
25 lines (16 loc) · 684 Bytes

how_do_you_create_custom_html_element_.md

File metadata and controls

25 lines (16 loc) · 684 Bytes

How do you create custom HTML element?

You can create a custom HTML element using the customElements.define method. Here's an example:

class MyElement extends HTMLElement {
  constructor() {
    super();
    this.innerHTML = '<p>Hello, Custom Element!</p>';
  }
}

customElements.define('my-element', MyElement);

// Usage in HTML:
// <my-element></my-element>

This defines a new custom element <my-element> which can be used like a standard HTML tag.

Tags: advanced, JavaScript, Web Components