<button id="new-button">Submit</button>
<!-- View the developer console in Chrome or Opera, or Firefox with the dom.webcomponents.enabled preference on, to see this working -->
JavaScript
/* Create a new prototype, extending the HTMLButtonElement interface */
var newBtnProto = Object.create(HTMLButtonElement.prototype);
/* Add example properties and methods to the new prototype */
newBtnProto.newProperty = 'foo';
newBtnProto.newMethod = function () {
console.log('New method!');
}
/* When the custom element has been used in the page, run a function to prove it */
newBtnProto.attachedCallback = function () {
console.log('Attached', this.newProperty);
};
/* Register the new element with the name 'new-button', state that it extends the button element, and that it should have the property and method defined in the extended prototype above */
var newBtn = document.registerElement('new-button', {
extends: 'button',
prototype: newBtnProto
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.