I use:
$(document.activeElement)
to return the current tabbed-to object.
Now, I need to know when I tab beyond the last tabbed-to object.
Note that each tabbable object is indicated with
.attr("tabindex", 0)
Just a hint would be nice, not the full-blown answer.
Here is what I have so far (2 approaches). Note that I have much more confidence in the 2nd approach, IF I could solve the line with “.find(…)”, which I know is wrong. I just do not know how to fix it.
function focusNextLI_1() {
$(document).ready(function() {
var $currFocusItem = getFocusedItem(), $nextFocusItem;
if ($currFocusItem[0].length === 0) {
// alert("TAB after .last() is already showing");
$nextFocusItem = $("li").first();
$nextFocusItem.focus();
}
});
} // focusNextLI_1
function focusNextLI_2() {
$(document).ready(function() {
var $currFocusItem = getFocusedItem(), $nextFocusItem;
const $everyLI = $("li");
const $currLI = $everyLI.find($currFocusItem); // ???
$nextFocusItem = $currLI.next();
if ($nextFocusItem.length === 0) {
// alert("TAB after .last() is already showing");
$nextFocusItem = $everyLI.first();
$nextFocusItem.focus();
}
});
} // focusNextLI_2
function getFocusedItem() {
return $(document.activeElement);
} // getFocusedItem