Extending Native Elements

suggest change

It’s possible to extent native elements, but their descendants don’t get to have their own tag names. Instead, the is attribute is used to specify which subclass an element is supposed to use. For example, here’s an extension of the <img> element which logs a message to the console when it’s loaded.

const prototype = Object.create(HTMLImageElement.prototype);
prototype.createdCallback = function() {
  this.addEventListener('load', event => {
      console.log("Image loaded successfully.");
  });
};

document.registerElement('ex-image', { extends: 'img', prototype: prototype });
<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:


Custom Elements:
* Syntax
* Extending Native Elements

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
40 Custom Elements
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde