JavaScripture
Contribute via GitHub Feedback

JavaScript CustomElementPrototype : HTMLElement

The prototype used for a custom element created with document.registerElement(). Use Object.create(baseType) to create the custom element prototype. The baseType must be an HTMLElement derived type and must match the prototype of the element set as the extends option passed to registerElement().

Instance Methods

attachedCallback() : undefined

Called when the custom element is inserted into the document or when the prototype is applied to elements already in the tree at the time document.registerElement() is called. See also MutationObserver.

Example:

Run

Results:

 

attributeChangedCallback(name : String, oldValue : Object, newValue : Object) : undefined

Called when an attribute was changed on the element. See also MutationObserver.

Example:

Run

Results:

 

createdCallback() : undefined

Called when the element is created.

Example:

Run

Results:

 

detachedCallback() : undefined

Called when the element is removed from the document. See also MutationObserver.

Example:

Run

Results:

 

Details

The following example demonstrates how to create a custom element based on HTMLElement.

Example:

Run

Results:

 

The following example demonstrates how to create a custom element based on a derivation of HTMLElement such as HTMLButtonElement.

Example:

Run

Results: