Extending Native Elements

suggest change

A customized built-in extends a native element, but it does not get its own tag name. The is attribute selects the subclass. document.registerElement and createdCallback are the removed v0 API. Current browsers use customElements.define. Safari does not support customized built-ins.

class ExImage extends HTMLImageElement {
  constructor() {
    super();
    this.addEventListener('load', () => {
      console.log("Image loaded successfully.");
    });
  }
}

customElements.define('ex-image', ExImage, { extends: 'img' });
<img is="ex-image" src="http://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png" />

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents