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.
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.
<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)
What am I doing wrong?
Seems like I solved the issue. I was missing the trigger.
Added:
window.onload = addAriaLabel;
and now works correctly.