How to allow keyboard tab focusing on div
tabindex
is a thing for divs. Set it to zero and native HTML5 will insert the correct tabindex
. Remember, all lower case:
<div tabindex=0> Stuff Here </div>
This will allow you to focus the div with the keyboard.
<div tabindex=0, autofocus=true> Stuff Here </div>
// select it with
document.querySelector("[autofocus]").focus();
// or with smelly jQuery
$([autofocus]).focus();
If you're using jQuery, you can find the focused div
easily with:
var $focused = $(':focus');
Then do things, like .click()
:
$focused.click()
This will click that thing.