Craig Celeste
Craig Celeste

Reputation: 12653

Set tabindex to a div accurately using jQuery

I have built a control using jQuery:

<div class="my-control" />
...
$('.my-control').myControl(); // builds it up as a ui element

Presently it is just a bunch of divs, spans, styles, mouse behaviors, etc. It does not get focus or participate in selection by tab.

I am finding the use of tabindex awkward in giving it focus. It is hard to know what value to give it. The control needs to inspect the rest of the document, be aware of other focusable controls, pay attention to when the rest of the document changes, etc.

Is it possible to say focusable=true and let it work out the tab order by document position, as normal?

Are there other techniques for doing this, other than tabindex?

Upvotes: 1

Views: 2734

Answers (1)

kapa
kapa

Reputation: 78671

tabindex="0" should be fine.

As the HTML5 spec on tabindex states:

If the value is a zero

The user agent must set the element's tabindex focus flag, should allow the element to be reached using sequential focus navigation, and should follow platform conventions to determine the element's relative order.

Upvotes: 1

Related Questions