Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict screen reader to not read a certain text?

Imagine, I have a <div> with aria-label as "Read this" (aria-label is added at runtime). Inside the <div>, I have a <span> with text "do not read this".

Now what Jaws is doing is, it reads both the text ("Read this" and "do not read this").

<div aria-label="Read this">
  <span>Do not read this</span>
</div>

The expectation is to only read "Read this". Is there anyway to restrict screen readers to force stop reading a text?

like image 885
Rajasekar Avatar asked May 04 '18 07:05

Rajasekar


People also ask

How do I get screen reader to ignore an element?

To hide an element to screen readers (and child elements), simply add the aria-hidden="true" attribute.

Does a screen reader read all of the text?

Typically, a screen reader will start at the top of a website or document and read any text (including alternate text for images). Some screen readers allow the user to preview information, like the navigation bar or all the headings on a page, and skip the user to the desired section of the page.

Do screen readers read hidden content?

Screen readers generally ignore anything with display: none, therefore it is not read out to screen readers. There are various ways of having things hidden visually or non-visually, so we'll run through the cases and techniques for each.


1 Answers

aria-hidden="true" is the thing you want

<div aria-label="Read this">
<span aria-hidden="true">Do not read this</span>
</div>

Note that not all screenreaders will read the aria-label on a div element and that it will result in a blank element

like image 138
Adam Avatar answered Sep 21 '22 00:09

Adam