Example 1 — Read ariaSelected
Log the selected token from a tab.
const el = document.getElementById("tab-id");
console.log(el.ariaSelected); // "true"
// HTML: <span id="tab-id" role="tab" aria-selected="true">First Tab</span> How It Works
- Find the tab.
getElementByIdreturns the tab node. - Read the reflection.
ariaSelectedreturns thearia-selectedstring. - Interpret
"true". Assistive technologies treat this tab as selected. - Missing attribute. If unset, many browsers return
null(tabs default to not selected).

