To get HTML element via aria label with JavaScript, we use the querySelector
or querySelectorAll
methods.
For instance, we write
const element = document.querySelector('[aria-label="Message Body"]');
to select the first element with the aria-label
attribute set to Message Body
.
Likewise, we write
const list = document.querySelectorAll('[aria-label="Message Body"]');
to select all the elements with the aria-label
attribute set to Message Body
returned in a node list.