customElements.define('wc-example',
class Alfa extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
this.content = document.createElement('div')
this.shadowRoot.append(this.content)
}
loadAttributes() {
const alfaAttrValue = this.hasAttribute('alfa')
? `Found alfa attribute with: ${this.getAttribute('alfa')}`
: "no alfa attribute in the element"
this.content.innerHTML = alfaAttrValue
}
connectedCallback() {
this.loadAttributes()
}
}
)