Search code examples
javascripthtmlfocusaccessibilitytabbing

html focus inputs with BOTH tabbing and focus()


Suppose I have

<input id="a" />
<a href="foo">foo</a>
<input id="b" />

By default tabbing will take me from a to foo to b. If I want to go from a to b directly I can do this

document .getElementById ("a") .setAttribute ("tabindex", 1);
document .getElementById ("b") .setAttribute ("tabindex", 2);

But now the following doesn't work because focus() apparently requires tabindex=-1

document .getElementById ("b") .focus ();

Can I have both?


Solution

  • It's started working all of a sudden, no idea what changed. Cached script perhaps.