Is it possible to access computed aria values from JS

I want to access the aria-expanded computed property on an element without it being present as an attribute. In chrome devtools's accessibility tab, the property exists as a computed property, but I can't figure out how to access this value via JS. Is it possible, or is just internal state in chrome that I don't have access to? element.ariaExpanded and element.getAttribute("aria-expanded") both just return null - so assume they are just trying to read the non-existent attribute, rather than the computed value.
No description
2 Replies
Chris Bolson
Chris Bolson3mo ago
That looks like a Chrome defined state to me rather than a computed aria attribute. Does such a thing (a computed aria attribute) even exist? I am fairly sure that aria attributes have to be specifically defined in the HTML (I may well be wrong about that). In my version of Chrome I wasn't able to see that "Expanded" value, probably due to the fact that it is out of date and they have stopped updating it for my OS. The only one of those "extra" definitions that I was getting was "Focusable". And even then I don't think that it is an "aria" attribute.
ἔρως
ἔρως3mo ago
it's just a fancy way to show the values of the attributes that are(n't) set it's way easier to read that list than 20 html attributes set in js and/or html also, some values are implicit for some elements, and this makes it easier to see that and points out the aria-labeledby element, instead of a "random" value that means nothing you see how it points out that it is being labelled by the <label> that has the for attribute set to that element? that is absolutely not the value you have set for aria-labelledby, as that isnt specified but it was computed to that label element, which is what the fancy list shows

Did you find this page helpful?