class CatCaption extends HTMLElement { static get observedAttributes() { return ['label']; } attributeChangedCallback(attr, oldValue, newValue) { if (attr == 'label') { this.changeText(newValue); } } connectedCallback() { //while (this.firstChild) this.insertBefore(this.firstChild, this.firstChild); //this.appendChild(this.span); } constructor() { super(); if (this.hasAttribute('label')) { this.changeText(this.getAttribute('label')); } } changeText(value) { var match = false; for (var i = 0; i < this.childNodes.length; i++) { if (this.childNodes[i].nodeType == 3) { this.childNodes[i].nodeValue = value; match = true; break; } } if (!match) { this.appendChild(document.createTextNode(value)); } } } customElements.define('cat-caption', CatCaption);