Reputation: 2584
Is it possible to assign a role to all elements with a given class? I'd want to turn this:
<div class="a" role="button">Text!</div>
<div class="a" role="button">More text!</div>
into this
<div class="a">Text!</div>
<div class="a">More text!</div>
<style>
.a {
role: button
}
</style>
I've found solutions for filtering by role in css but nothing to assign a role to elements using css.
Upvotes: 2
Views: 1159
Reputation: 3480
You can achieve with pure JavaScript through forEach() method.
document.querySelectorAll(".a").forEach(function(role){
role.setAttribute('role', 'button');
});
<div class="a">Text!</div>
<div class="a">Text #2</div>
<div class="a">More text!</div>
Upvotes: 0
Reputation: 337
let buts = document.getElementsByClassName("a");
for(let i = 0; i < buts.length; i++){
buts[i].setAttribute("role", "button");
}
<div class="a">Text!</div>
<div class="a">More text!</div>
Upvotes: 2