UNPKG

@underpostnet/underpost

Version:
45 lines (34 loc) 1.19 kB
// https://javascript.info/ // https://javascript.info/web-components class MyElement extends HTMLElement { constructor() { super(); // element created } connectedCallback() { // browser calls this method when the element is added to the document // (can be called many times if an element is repeatedly added/removed) } disconnectedCallback() { // browser calls this method when the element is removed from the document // (can be called many times if an element is repeatedly added/removed) } static get observedAttributes() { return [ /* array of attribute names to monitor for changes */ ]; } attributeChangedCallback(name, oldValue, newValue) { // called when one of attributes listed above is modified } adoptedCallback() { // called when the element is moved to a new document // (happens in document.adoptNode, very rarely used) } // there can be other element methods and properties } customElements.define('my-element', MyElement); // Now for any HTML elements with tag <my-element>, // an instance of MyElement is created, and the aforementioned // methods are called. export { MyElement };