Web APIs

observedAttributes

Try the free JavaScript compiler

Names of attributes whose changes trigger the custom element attribute reaction.

Formal Syntax & Structure

javascript syntaxjavascript
static observedAttributes = ["count"]

Working Example

Example Snippetjavascript
(async () => {const changes=[];class LessonCount extends HTMLElement{static observedAttributes=["count"];attributeChangedCallback(name,oldValue,newValue){changes.push([name,oldValue,newValue]);}}customElements.define("lesson-count",LessonCount);const x=document.createElement("lesson-count");x.setAttribute("count","2");x.setAttribute("count","3");x.removeAttribute("count");console.log(JSON.stringify(changes));})()
JavaScript Reference