I have buttons that are div elements and I want to make them so that it is possible for the user to press the tab key on their keyboard and move between them. I've tried wrapping their text in anchor tags but it doesn't seem to work.
Does anyone have a solution?
Add
tabindex
attributes to yourdiv
elements.Example:
Per steveax's comment, if you don't want the tab order to deviate from where the element is in the page, set the
tabindex
to0
:Add the
tabindex="0"
attribute to each div you want tabbable. Then use CSS pseudo classes :hover and :focus, for example to signify to the app user that the div is in focus and clickable, for example. Use JavaScript to handle the click.for those interested, in addition to the accepted answer, you can add the following jquery to make the div style change when you tab to it, and also handle Enter and Space to trigger a click (then your click handler will do the rest)
I'm sure someone has made this into a jq plugin $().makeTabStop