Skip hidden tab indices
I have the following html:
<span tabindex="19">
</span>
<span tabindex="20">
</span>
<span tabindex="21">
</span>
<span id="hidden" tabindex="22">
</span>
<span tabindex="23">
</span>
<span tabindex="24">
</span>
As you can see one of the flights is hidden, the code to hide it,
#hidden
{
display: none;
}
I need a behavior where the tab skips hidden indices. So I want something like this when I click the tab: go to 19,20,21,23,24
I have no way to manage the indexes of the tabs as they are hardcoded in the html i process.
+3
source to share
4 answers
You can give it a negative tabindex that should be ignored by the browser. JQuery plugins do this as well, like SkipOnTab https://github.com/joelpurra/skipontab .
var $hidden = $('#hidden');
$hidden.attr('tabindex', '-' + $hidden.attr('tabindex'));
0
source to share
Usually the tab-event function will automatically skip over the invisible HTML element. However, the hard-coded portion of the HTML can override JavaScript after the page has loaded:
<script>
window.addEventListener("load", function()
{
document.getElementById("hidden").setAttribute("tabindex", "-1");
});
</script>
JQuery is also a solution, but 90kByte is a bit heavy for this simple task.
0
source to share