Web APIs

aria-expanded state

Try the free JavaScript compiler

Communicates the expanded/collapsed state of a disclosure control. The application must separately update the controlled content visibility.

Formal Syntax & Structure

javascript syntaxjavascript
button.setAttribute("aria-expanded", String(expanded))

Working Example

Example Snippetjavascript
const b=document.createElement("button"),p=document.createElement("section");b.textContent="Details";p.id="details-panel";p.hidden=true;b.setAttribute("aria-controls",p.id);b.setAttribute("aria-expanded","false");b.addEventListener("click",()=>{p.hidden=!p.hidden;b.setAttribute("aria-expanded",String(!p.hidden));});b.click();console.log(b.getAttribute("aria-expanded"),p.hidden);
JavaScript Reference