JSFiddle - React, Tailwind, and code Playground

by Deepak Anand

HTML

<div id = 'place'></div>

JavaScript

// Widget API exploration using CustomElement - 3

class MyWidget extends HTMLElement{

	constructor() {
   super()
   this.api = {}
   
   this.api.setLabel = this.setLabel.bind(this)
  }
	
  setLabel(value) {  	
  	this.label = value
  } 

	connectedCallback() {
  	console.log('in dom')
  	this.innerHTML = '<div> My name is <span></span>'
  }
  
	set label(value){
  	console.log(value)
  	var spanElt = this.querySelector('span')
    spanElt.textContent = value
  }
  
}


window.customElements.define('my-widget', MyWidget)

var widget = new MyWidget()
document.querySelector('#place').appendChild(widget)
widget.api.setLabel('foo')