Source Code:
(back to article)
Submit
Result:
Report an issue
<div> <script> class LifecycleComponent extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); } connectedCallback() { this.shadowRoot.innerHTML = '<p>Element added to page.</p>'; } disconnectedCallback() { console.log('Element removed from page.'); } } customElements.define('lifecycle-component', LifecycleComponent); </script> <lifecycle-component></lifecycle-component> </div>