易学问答
  • 首页
  • 话题
  • 动态
  • 专家
  • 文章
  • 作者
  • 公告
  • 更多
    • 积分规则
登录 或 注册
  • 首页
  • 话题
  • 动态
  • 专家
  • 文章
  • 作者
  • 公告
  • 积分规则
 发表新帖
发表新帖

Updating keyboard focus when implementing the skip to main content technique through an anchor link

前端 未结
关注
 1  1303
遇见更好的自我
遇见更好的自我 2021-01-24 20:38

I\'m implementing the skip to main content technique described in W3C\'s WCAG2.0 Techniques documentation, however I\'m struggling to update the keyboard focus when act

1条回答
  •  独厮守ぢ
    独厮守ぢ (楼主)
    2021-01-24 21:27

    From your comment, 'window.location.hash' is empty on click.

    I would also suggest that you apply tabindex="-1" rather than 0, which means the main is in the tab-order. Using -1 means you can programmatically focus on the element, but it is not in the default order.

    Also, for posterity (and people finding this later) my generally solution would be to use something like this:

    HTML Skip link:

    Skip to content
    

    HTML Target:

    JS:

    $("#skiplink").click(function() {
        $('main').focus();
    });
    

    CSS:

    main:focus {outline: 0;}
    

    You can of course apply more of that through JavaScript, that's up to you.

    It might help to put the tabindex attribute in the HTML.

    0 讨论(0)
    提交评论

    •  加载中...
 看不清?
提交回复
热议问题