Skip to content

Web Components

The Web Components lifecycle: constructor, connected, attributeChanged, adopted and disconnected callbacks.

1 min read

Lifecycle

constructor()

It creates and initializes an object instance of the class. In the web component lifecycle, the constructor is the first method of the lifecycle and is called once the web component is initialized.

connectedCallback()

It will be called once each time the web component is attached to the DOM.

attributeChangedCallback()

It will be called every time that attribute is updated. To observe the attributes, you hava to use static get observedAttributes() method. It is placed right at the top of the constructor and should return an array, containing the names of the attributes you want to observe:

static get observedAttributes() { return ['attribute1', 'attribute2']; }

adoptedCallback()

It is used to move a node from one document to another.

disconnectedCallback()

It will be called when the web component is removed from the DOM.

Related articles

12 min read

Frontend Checklist

A front-end checklist covering meta tags, HTML, CSS, JavaScript, performance, SEO, accessibility and security.

  • Web & Frontend
1 min read

SVG

Dynamic fills and strokes for SVG background images in CSS.

  • Web & Frontend
8 min read

JSF

Jakarta Faces (JSF) notes: WebSocket push, scopes, events, Ajax, security and cross-field validation.

  • Java & Jakarta EE
  • Web & Frontend

Type to search the whole site.