Vic_O Posted January 18 Share Posted January 18 Hello, I am working my way through a lighthouse report and fixing some accessibility issues. https://www.116pallmall.com/ Link text (and alternate text for images, when used as links) that is discernible, unique, and focusable improves the navigation experience for screen reader users. Learn how to make links accessible. Failing Elements div.Header-social > nav.SocialLinks > div.SocialLinks-inner > a.SocialLinks-link <a href="https://www.instagram.com/116pallmall/" target="_blank" class="SocialLinks-link instagram-unauth" style=""> div.Header-social > nav.SocialLinks > div.SocialLinks-inner > a.SocialLinks-link <a href="https://www.linkedin.com/company/116-pall-mall" target="_blank" class="SocialLinks-link linkedin-unauth" style=""> div.Header-social > nav.SocialLinks > div.SocialLinks-inner > a.SocialLinks-link <a href="https://www.facebook.com/116pallmall/" target="_blank" class="SocialLinks-link facebook-unauth" style=""> div.Header-social > nav.SocialLinks > div.SocialLinks-inner > a.SocialLinks-link <a href="https://twitter.com/116PallMall" target="_blank" class="SocialLinks-link twitter-unauth" style=""> Any tips on how to fix please - thanks! Link to comment
DanFar Posted January 18 Share Posted January 18 I have the same issue Links do not have a discernible name News years Resolution? Help us find <a href="https://www.instagram.com/p/D3VfSds/" class=" image-slide-anchor …" style="overflow: hidden;"> Any help? Link to comment
Solution jpeter Posted January 19 Solution Share Posted January 19 (edited) @Vic_O @DanFar You can add an aria-label attribute on the <a> tag for each social media link by adding the following JavaScript to the Footer using Code Injection: (function(){ // Add aria-label to Instagram link document.querySelectorAll('.instagram-unauth') .forEach(el => el.setAttribute('aria-label', 'Instagram')); // Add aria-label to Facebook link document.querySelectorAll('.facebook-unauth') .forEach(el => el.setAttribute('aria-label', 'Facebook')); // Add aria-label to Twitter link document.querySelectorAll('.twitter-unauth') .forEach(el => el.setAttribute('aria-label', 'Twitter')); // Add aria-label to LinkedIn link document.querySelectorAll('.linkedin-unauth') .forEach(el => el.setAttribute('aria-label', 'LinkedIn')); })() Be sure to add the JS between <script> tags, e.g. <script> // Add JS here </script> Edited January 19 by jpeter Vic_O 1 Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee! Link to comment
DanFar Posted January 19 Share Posted January 19 I have the same issue Links do not have a discernible name News years Resolution? Help us find <a href="https://www.instagram.com/p/D3VfSds/" class=" image-slide-anchor …" style="overflow: hidden;"> So my code will look like ? // Add aria-label to Instagram link document.querySelectorAll('.image-slide-anchor') .forEach(el => el.setAttribute('aria-label', 'Instagram')); Its like 4-5 links with different Instagram stories, how can I pick up the name of the post and use that as a ARIA-Label Thank you Link to comment
jpeter Posted January 22 Share Posted January 22 @DanFar for your case, I would use following code to target each individual link leveraging the a[href^="<URL>"] CSS attribute selector as the string in the querySelectorAll method: (function(){ // Add aria-label to Instagram story link document.querySelectorAll('a[href^="https://www.instagram.com/p/D3VfSds/"]') .forEach(el => el.setAttribute('aria-label', 'My Story')); // Add aria-label to Instagram story link document.querySelectorAll('a[href^="https://www.instagram.com/p/TEST124/"]') .forEach(el => el.setAttribute('aria-label', 'My Story 2')); })() Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee! Link to comment
Vic_O Posted January 24 Author Share Posted January 24 On 1/19/2024 at 7:02 AM, jpeter said: @Vic_O @DanFar You can add an aria-label attribute on the <a> tag for each social media link by adding the following JavaScript to the Footer using Code Injection: (function(){ // Add aria-label to Instagram link document.querySelectorAll('.instagram-unauth') .forEach(el => el.setAttribute('aria-label', 'Instagram')); // Add aria-label to Facebook link document.querySelectorAll('.facebook-unauth') .forEach(el => el.setAttribute('aria-label', 'Facebook')); // Add aria-label to Twitter link document.querySelectorAll('.twitter-unauth') .forEach(el => el.setAttribute('aria-label', 'Twitter')); // Add aria-label to LinkedIn link document.querySelectorAll('.linkedin-unauth') .forEach(el => el.setAttribute('aria-label', 'LinkedIn')); })() Be sure to add the JS between <script> tags, e.g. <script> // Add JS here </script> Legend! Thank you!! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment