WebAIM - Web Accessibility In Mind

E-mail List Archives

Is it okay to change ARIA role with JavaScript after page load?


From: Robert Fentress
Date: Jul 30, 2018 10:19AM

I thought I'd remembered reading somewhere that best practice was not to
change the role of an existing element using JavaScript after the page has
loaded, but, rather, to recreate the element with the new role. However, I
can't seem to find where I'd read that initially or what exactly the
justification was for that. Certainly, unless JavaScript is intrinsic to
the functioning of the resource, progressive enhancement would suggest that
for any interactive widget role, you should not include the role inline.
This is because without scripting, the user may be presented with incorrect
cues and affordances. The Using ARIA Editor's Draft
<https://w3c.github.io/using-aria/#inline> seems to suggest the role should
be added with JavaScript, but doesn't say anything about needing to
recreate the element to do so.

So, is this actually an issue and why? Is it because the Accessibility
Tree is not always updated reliably if you change roles with JavaScript?
Or perhaps screen readers that don't access the Accessibility APIs directly
may not track these changes? If so, which assistive technologies might
still have this problem?



*Rob Fentress*
*Web Accessibility Solutions Designer*
Accessible Technologies at Virginia Tech
Electronic Business Card (vCard)
LinkedIn Profile
VT Zoom Personal Conferencing <https://virginiatech.zoom.us/my/rob.fentress>