开发者

How can I programatically focus on an element (tab into it)?

I need to make elements of a page accessible with keyboard so users can tab through the page. I managed this bit, but I need as well to be able to programatically tab into certain anchor elements (anchor tag <a></a>).

$('#elementid').focus() doesn't do the trick; it doesn't give the same effect as using the keyboard tab to reach the element (no dotted border around the element for instance in firefox/ie).

Do you know how I can开发者_StackOverflow社区 do this, how can I simulate tabbing into an elements with javascript or jquery?


As far as I know, you may not.

.focus is the proper way to gain keyboard focus on input elements, but you won't be able to focus on arbitrary nodes.

The "dotted border" is simply a UI mechanism used by browsers for a visual cue when you are using the TAB key to iterate through nodes: it has no semantic value and no relevance to a programmatic solution.

If you wish to style your elements, use CSS.


From your comments, it sounds like maybe you actually meant to ask how to manipulate the tab order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜