Hey im trying to get every single element on a page that has an aria label that contains/starts with "i_". I also need to do this in javascript.
thanks
In CSS, you would use the [attribute^=value] format:
[aria-label^="i_"] {
background: #55ff55;
}
In JavaScript, just use the same thing:
document.querySelectorAll("[aria-label^='i_']");
That should return an array-like list of all the elements with aria-label values that start with i_.
Here's an example with both of them:
var x = document.querySelectorAll("[aria-label^='i_']");
// 'x' contains all of the <p> elements that have "i_" in the start
[aria-label^="i_"] {
background: #55ff55;
}
<p aria-label="i_foo"> Giraffes have black tongues to protect them from getting sunburnt </p>
<p aria-label="i_bar"> Coral colonies can live up to centuries old </p>
<p aria-label="m_foo"> The moon is a planet </p>
<p aria-label="i_gaw"> Ostriches' eyes are larger than their brains </p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With