Example 1 — Read ariaRequired
Log the current required token from a custom textbox.
const el = document.getElementById("txtBoxInput");
console.log(el.ariaRequired); // "true"
// HTML: role="textbox" aria-required="true" … How It Works
- Find the widget.
getElementByIdreturns the custom textbox node. - Read the reflection.
ariaRequiredreturns thearia-requiredstring. - Interpret
"true". Assistive technologies treat the field as required before submit. - Missing attribute. If there is no
aria-required, many browsers returnnull.

