Example 1 — Read ariaPressed
Log the current pressed token from a toggle button.
const el = document.getElementById("saveChanges");
console.log(el.ariaPressed); // "false"
// HTML: <button type="button" id="saveChanges" aria-pressed="false">Save</button> How It Works
- Find the control.
getElementByIdreturns the toggle button node. - Read the reflection.
ariaPressedreturns thearia-pressedstring. - Interpret
"false". The control can be pressed, but it is currently off. - Missing attribute. If there is no
aria-pressed, many browsers returnnull.

