Extending Native Elements
suggest changeA 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" />
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents