Concepts
Boolean property reflection
A custom property can reflect presence of an attribute; assigning false should remove it under this convention.
Formal Syntax & Structure
javascript syntaxjavascript
get active() { return this.hasAttribute("active"); }Return Value
boolean
A custom property can reflect presence of an attribute; assigning false should remove it under this convention.
Working Example
Example Snippetjavascript
(async () => {class LessonToggle extends HTMLElement{get active(){return this.hasAttribute("active");}set active(v){this.toggleAttribute("active",Boolean(v));}}customElements.define("lesson-toggle",LessonToggle);const x=document.createElement("lesson-toggle");x.setAttribute("active","false");const before=x.active;x.active=false;console.log(before,x.hasAttribute("active"));})()