DanC
DanC

Reputation: 8805

HTML where will the focus go next if I press tab?

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!

Upvotes: 8

Views: 14868

Answers (6)

Tracker1
Tracker1

Reputation: 19334

It would be very complicated to do this via script, essentially (typically) input types (including select, textarea, button) etc along with links (a tags) and label tags bound to an input tag are able to be focused, unless the tabindex property is set, the next tag in your markup that is one of the above types/conditions will be the next focused.

Upvotes: 1

Alohci
Alohci

Reputation: 82976

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.

Upvotes: 7

the_void
the_void

Reputation: 5538

I think you could use the jquery.Listen library to accomplish this.

Something like this:

jQuery('table').listen( 'focusin', 'tr', function(){
    alert("you've focused on a row!");
});

Upvotes: 0

Damien Dennehy
Damien Dennehy

Reputation: 4064

Use HTML's TABINDEX attribute to control where the tab goes.

<input name="email" tabindex="1"></input>
<input name="phone" tabindex="2"></input>

Upvotes: 9

websch01ar
websch01ar

Reputation: 2123

So long as you have set the tabindex for all objects on the page, you will be able to use javascript to find the next increment from the current object.

Upvotes: 0

Steve Sheldon
Steve Sheldon

Reputation: 6621

Maybe you can use the DOM to enumerate the inputs on the page and read the tabindex property.

Upvotes: 1

Related Questions