Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all display:none attributes and add in aria-hidden attribute using JavaScript

Is there a way to search for all the instances where property display:none is used and add the attribute aria-hidden="true" using JavaScript.

My site has hundreds of instances of this and i am looking for a quicker way.

Could it be something like this: (added to a function)

$(*).css( "display", "none" ).attr( "aria-hidden", "true" );
like image 267
Smithy Avatar asked Dec 01 '25 23:12

Smithy


2 Answers

The effect of aria-hidden="true" is to instruct the browser to not expose the element to the accessibility tree even if it is not hidden.

The browsers do not expose any elements to the accessibility API that are display:none.

So what you are trying to do is totally redundant. It will have absolutely zero additional affect on accessibility. Save yourself the effort and do something more productive.

like image 181
unobf Avatar answered Dec 04 '25 12:12

unobf


use hidden() selector to identify all display none element

$( ":hidden").attr( "aria-hidden", "true" );

DEMO

like image 44
Balachandran Avatar answered Dec 04 '25 12:12

Balachandran



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!