Web Component Example: Just Some HTML
This is a super basic Web Component. All it does is output some HTML.
JavaScript
customElements.define('wc-widget',
class Widget extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
this.content = document.createElement('div')
this.content.innerHTML = 'This is a web component'
this.shadowRoot.append(this.content)
}
}
)
HTML
<wc-widget></wc-widget>
Output