Is there some way of knowing where will the focus jump to when the tab key key will be pressed and certain element has the focus?
I am thinking on something to be used this way:
var nextElement = whereWillFocusJumpTo(currentElement);
Thanks!
The HTMLElement. focus() method sets focus on the specified element, if it can be focused. The focused element is the element that will receive keyboard and similar events by default.
In most browsers, users can move focus by pressing the Tab key and the Shift + Tab keys. The following elements can receive focus: <a> tags with an href attribute.
In summaryThe href attribute set to the URL of the page you want to link to. The target attribute set to _blank , which tells the browser to open the link in a new tab/window, depending on the browser's settings.
An element can be focused by either using the autofocus="true" attribute or calling the element. focus() method. In both cases, the browser will automatically scroll the element into the viewport.
Use HTML's TABINDEX attribute to control where the tab goes.
<input name="email" tabindex="1"></input>
<input name="phone" tabindex="2"></input>
The algorithm for determining the tab order is here:-
http://dev.w3.org/html5/spec/editing.html#sequential-focus-navigation
One thing to note is that if more than one element has a tabindex of 0, the tab order is platform dependent, so you may wish to ensure that all focusable elements on your page have a non-zero tabindex.
Maybe you can use the DOM to enumerate the inputs on the page and read the tabindex property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With