Menu Close

How to get HTML element via aria label with JavaScript?

How to get HTML element via aria label with JavaScript
Here, we learn about 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.

So we can 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.

Posted in HTML, JavaScript

You can also read...