简体   繁体   English

查找所有display:none属性,并使用JavaScript添加aria-hidden属性

[英]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. 有没有一种方法可以搜索所有使用display:none属性的实例,并使用JavaScript添加属性aria-hidden="true"

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" );

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. aria-hidden="true"是指示浏览器即使未隐藏该元素也不向可访问性树公开。

The browsers do not expose any elements to the accessibility API that are display:none . 浏览器不会向显示可访问性API的任何元素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. 节省您的精力,并提高工作效率。

use hidden() selector to identify all display none element 使用hidden()选择器识别所有不显示元素

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

DEMO 演示

EDIT: 编辑:

You can use filter, but it is not optimal solution: 您可以使用过滤器,但这不是最佳解决方案:

$("*").filter(function() { return $(this).css("display") == "none" })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM