Dynamically adding aria-describedby using JavaScript

posted by sacah on javascript, programming, sacah,

Just a quick one to let others know what I’ve found, while it seems many of the ARIA tags work happily when added dynamically, aria-describedby will only work if it’s present when the DOM is rendered, after that screen readers just won’t see it.

The simple ways around this seem to be adding random unique aria-describedbys to all your elements, then dynamically changing the ID of what you want to point too.

Or use a global aria-live element that you change the text in to match the text you would have pointed to with aria-describedby.