Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set tabindex for button not working

I have few controls on a form. I have to set the tabIndex in an order that is not natural to their order of creation on HTML. There is a button at the fag end and the tabIndex is not getting set (it's never focussed) only on this element.

<button id="btnSave" tabindex = "86" title='click here'>Submit Here</button>

What may be the reasons??

Appreciate your help.

like image 865
Premanshu Avatar asked Jan 20 '12 11:01

Premanshu


People also ask

Can I use Tabindex for Button?

The tabindex attribute specifies the tab order of an element (when the "tab" button is used for navigating). The tabindex attribute can be used on any HTML element (it will validate on any HTML element.

What does Tabindex =- 1 mean?

A negative value (usually tabindex="-1" ) means that the element is not reachable via sequential keyboard navigation, but could be focused with JavaScript or visually by clicking with the mouse. It's mostly useful to create accessible widgets with JavaScript.

What is the difference between Tabindex 1 and Tabindex 0?

tabindex="1" (or any number greater than 1) defines an explicit tab or keyboard navigation order. This must always be avoided. tabindex="0" allows elements besides links and form elements to receive keyboard focus.


2 Answers

Tabindex Best Practices

Commonly, I would suggest that do not set Tabindex with any incremental values because for any fields/components in your web page if we follow this rule then we need to maintain the same tabindex incremental values for upcoming fields too and also we mostly show/hide the fields/components based on some conditions so that time the tab index will not work consistently.

I strongly suggest the best practice is that we should not use Tabindex Greater than 0 and use only Tabindex -1 and 0 wherever required

tabindex="-1"

Setting tabindex="-1" allows you to set an element’s focus with the script, but does not put it in the tab order of the page. This is handy when you need to move focus to something you have updated via script or outside of user action.

tabindex="0"

Setting tabindex="0" will take an element and make it focusable. It doesn’t set the element’s position in the tab order, it just allows a user to focus the element in the order determined by its location with the DOM.

tabindex="1" (or any value > 0)

Do not set a tabindex="1" or any value greater than zero (or any positive value).

like image 114
Ganesa Vijayakumar Avatar answered Sep 28 '22 05:09

Ganesa Vijayakumar


If you set tabindex only on the button element, then this element will be the first in navigation, which means that you don’t get to it from the last input field directly (but only via some browser-dependent items in the browser’s own user interface, such as search box and address box). See the HTML 4.01 spec on tabindex.

If you have set tabindex on other fields as well, please post a demo that exhibits the behavior—in a simple test on several browsers, tabindex worked fine when set on all fields.

like image 27
Jukka K. Korpela Avatar answered Sep 28 '22 07:09

Jukka K. Korpela