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

折月煮酒 提交于 2019-12-02 06:24:47

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:

<a href="#main" id="skiplink">Skip to content</a>

HTML Target:

<main role="main" id="main" tabindex=”-1”>

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!