Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add aria-label on button

How do I add aria-label to a button? From:

<button type="button" class="owl-dot active"><span></span></button> 

to:

<button role="button" aria-label="slide-dot" class="owl-dot active"><span></span></button> 

I've tried to use document.getElementById('owl-dot').setAttribute('aria-label', 'slide-dot'); but it's not working.

like image 314
Sarah C Avatar asked Oct 23 '25 18:10

Sarah C


1 Answers

Your solution is correct, please make sure it runs after DOM is ready.

document.getElementById('owl-dot').setAttribute('aria-label', 'slide-dot')

In fact, you do not need to add aria-label for current button DOM since the inside content could be read out instead.

The aria-label should be added to button DOM only when:

  1. The DOMs inside are have too many levels, then the count string might not be read out.
  2. The aria-label is different from inside content string.
like image 153
su lin Avatar answered Oct 26 '25 07:10

su lin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!