javascript - Does document.getElementById("someId").innerHTML = `${someVar}` set a value that is accessible to screen readers?
问题描述
Preamble: I am only interested in getting info about DOM API, HTML, and Vanilla JS for my current project. I am not interested in jQuery at the moment, so please do not offer me advice or solutions with jQuery. Thanks for understanding. If there is a tutorial that will tell me about how to test for accessibility, or if you have some ways for me to troubleshoot similar issues in the future, I would love to hear it.
I came across the concept of the shadow DOM today, and I looked up its accessibility. I read through this: https://marcysutton.com/accessibility-and-the-shadow-dom.
I am trying to create HTML that has elements whose values are updated by JavaScript. I have settled for the moment on using document.getElementById().innerHTML = ''
to test this out.
I have a pen here: https://codepen.io/coscholl/pen/qBbYNPY
You can see that these D&D ability scores are created by a function and added by the DOM method. If this is not accessible, I want to make an accessible version. So, is this method accessible to screen readers and the like?
Thanks!
解决方案
Yes. It is screen readable. There is nothing inherently wrong with using .innerHTML
from a screen reader or accessibility standpoint.
Using .innerHTML
while the assignment value is text will create a text node which you can verify by inspecting the DOM. However, best practice would dictate using .textContent
for replacing element text.
推荐阅读
- java - Eclipse 在调试时显示 Java 字节数组的红色值
- c# - 我应该如何处理一对多关系来填充数据模型
- c - 在 Linux 中重置忽略信号的掩码
- google-analytics - 如何在 GTM 中跟踪外部(添加 js)HTML
- rxjs - Observable.forEach 发生了什么错误和完成回调?
- visual-studio-2015 - 检查文件夹中是否存在文件(SSIS 和 SQL Server 2014/2016)
- excel - 数据整合:结合每月试算表
- php - url 匹配时静默传递查询
- python - 即使将实例提供给 ModelForm,重复的键值也会违反唯一约束
- c# - 将变量从窗口传递到页面