Although manipulating the prose in your ebook by script is forbidden, it doesn’t mean you can’t dynamically insert or modify any text. Automatically displaying the result of a quiz or displaying the result of a calculation are a just a couple of examples of cases where dynamic prose updates would legitimately be useful for readers. You may also want to provide informative updates, such as the number of characters remaining in an entry field.
The problem with these kinds of dynamic updates is how they’re made available to readers using accessible technologies. When you update the main document by re-writing the inner text or html of an element, how that change gets reported to the accessible technology, if at all, is out of your control in plain old HTML.
The update could force the reader to lose their place and listen to the changed region every time, or it could be ignored entirely. ARIA has solved this problem with the introduction of live regions, however.
If you’re going to use an element to insert dynamic text, you mark this purpose
by attaching an aria-live attribute to it. The
value of this attribute also tells an assistive technology how to present the
update to the reader. If you set the value polite,
for example, the assistive technology will wait until an idle period before
announcing the change (e.g., after the user is done typing for character
counts). If you set it to assertive, the reading
system will announce the change immediately (e.g., for results that the reader
is waiting on).
You could set up a simple element to write results to with no more code than follows:
<div id="result" aria-live="assertive"/>
Now when you write using the innerHTML property, the
new text will be read out immediately. Be careful when using the assertive setting, however. You can annoy your
readers if their system blurts out every inconsequential change you might happen
to write as it happens.
If you write out results a bit at a time, or need to update different elements
within the region, the aria-busy attribute should
be set to true before the first write to indicate
to the reading system that the update is in progress. If you don’t, the reading
system will announce the changes as you write them. So long as the state is
marked as busy (true), however, the reading system
will wait for the state to be changed backed to false before making any announcement.