2

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" );
Kalu Singh Rao
  • 1,671
  • 1
  • 16
  • 21
Smithy
  • 771
  • 10
  • 29

3 Answers3

9

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.

unobf
  • 7,158
  • 1
  • 23
  • 36
  • Screen reader still reads out content that has the display:none attribute so the aria-hidden is in fact required – Smithy Jun 13 '15 at 14:43
  • 1
    @RAS that is absolute poppycock – unobf Jun 13 '15 at 23:59
  • 2
    @RAS here is a reference to one of the specs that talks about when content should not be exposed to the accessibility tree http://www.w3.org/TR/core-aam-1.1/#h-exclude_elements2 – unobf Jun 14 '15 at 00:09
  • 1
    @Tin Both `display: none` and `visibility: hidden` aren't exposed by SR. Other declarations may or may not depending on SR (`opacity:0`, etc) but those 2 ones are perfectly safe to use – FelipeAls Jun 22 '15 at 14:52
5

use hidden() selector to identify all display none element

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

DEMO

Balachandran
  • 9,567
  • 1
  • 16
  • 26
0

EDIT:

You can use filter, but it is not optimal solution:

$("*").filter(function() { return $(this).css("display") == "none" })
suvroc
  • 3,058
  • 1
  • 15
  • 29