Skip to content

Lifecycle callback methods

Glenn Vandeuren edited this page Nov 14, 2017 · 5 revisions

Custom Elements V1

Name Called when
constructor An instance of the element is created or upgraded. Useful for initializing state, settings up event listeners, or creating shadow dom. See the spec for restrictions on what you can do in the constructor.
connectedCallback An instance of the element is inserted into the DOM. Useful for running setup code, such as fetching resources or rendering. Generally, you should try to delay work until this time.
disconnectedCallback An instance of the element is removed from the DOM. Useful for running clean up code (removing event listeners, etc.).
attributeChangedCallback(attrName, oldVal, newVal) An attribute was added, removed, updated, or replaced. Also called for initial values when an element is created by the parser, or upgraded. Note: only attributes listed in the observedAttributes property will receive this callback.
adoptedCallback The custom element has been moved into a new document (e.g. someone called document.adoptNode(el)).
Clone this wiki locally