简体   繁体   English

将 Aria Label 添加到链接

[英]Add Aria Label to a Link

trying to make a website accessible.试图使网站可访问。 There is a close menu button that's missing an Aria Label and i'm trying to add one by using JS.有一个关闭菜单按钮缺少 Aria Label,我正在尝试使用 JS 添加一个。

I'm using the following script in order to target the ID and add the attribute, but while the script loads, the aria label is not added.我正在使用以下脚本来定位 ID 并添加属性,但是在加载脚本时,没有添加 aria label。

 <script> function addAriaLabel() { // Create an aria label attribute: const addAria = document.createAttribute("aria-label"); // Set the value of the aria-label attribute: addAria.value = "close button"; // Add the href attribute to an element: document.getElementById("cart-accessibility").setAttributeNode(addAria); } </script>

For reference the location of the element is https://outletbrands.gr/shop-2 (the filters closing button)作为参考,元素的位置是https://outletbrands.gr/shop-2 (过滤器关闭按钮)

What am I doing wrong?我究竟做错了什么?

Seems like I solved the issue.好像我解决了这个问题。 I was missing the trigger.我错过了触发器。

Added:添加:

window.onload = addAriaLabel; window.onload = addAriaLabel;

and now works correctly.现在可以正常工作。

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

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