Getting the tabindex value with JavaScript on elements without a tabindex attribute
Simon Bates
simon.bates at utoronto.ca
Fri Dec 14 21:55:25 UTC 2007
I have been writing a function for Dojo's DHTML accessibility support
that determines if an element is tab-navigable. The function will use
the extended tabindex usage defined by the current ARIA and HTML5
drafts. That is, tabindex on all elements, and tabindex="-1" for removal
from tab order. I have discovered that there is some variation across
browsers in the value that one gets when retrieving the tabindex value
on an element without a tabindex attribute. This note summaries what I
have seen.
I have looked at two elements: div and input. I am using div as an
example of an element that did not have a tabindex attribute in HTML4
and input as an example of one that did. I document here two mechanisms
for retrieving the tabindex: getAttribute(), and the tabIndex property.
Please see below for a link to my test file and a link to the full results.
Firefox 2.0.0.11 Windows XP
and Minefield nightly 3.0b3pre 2007121405 Windows XP
div with no tabindex:
elem.getAttribute("tabindex") = null
elem.tabIndex = -1
input with no tabindex:
elem.getAttribute("tabindex") = null
elem.tabIndex = 0
Internet Explorer 7.0.5730.11 Windows XP
and Internet Explorer 6 Windows XP
div with no tabindex:
elem.getAttribute("tabindex") = 0
elem.getAttribute("tabindex", 2) = 32768
elem.tabIndex = 0
input with no tabindex:
elem.getAttribute("tabindex") = 0
elem.getAttribute("tabindex", 2) = 32768
elem.tabIndex = 0
On IE it is not possible to determine whether a div has no tabindex or
tabindex="0" using elem.getAttribute("tabindex") or elem.tabIndex
because a default value of 0 is returned. Microsoft provides an
extension to getAttribute() that can be used to determine if the
tabindex is unset. If a second parameter of value "2" is passed to
getAttribute(), a value of 32768 is returned whenever tabindex is not
set. See Microsoft's documentation on getAttribute:
http://msdn2.microsoft.com/en-us/library/ms536429.aspx
I have been unable to find documentation on the value of 32768 as used
for tabIndex but it is outside of the range of 0 to 32767 specified by
HTML 4:
http://www.w3.org/TR/html401/interact/forms.html#adef-tabindex
Safari 3.0.4 Mac
div with no tabindex:
elem.getAttribute("tabindex") = null
elem.tabIndex = undefined
input with no tabindex:
elem.getAttribute("tabindex") = null
elem.tabIndex = 0
Test file used to gather results:
http://trac.bitstructures.com/browser/collected/trunk/html-test-cases/getting-tabindex.html?format=raw
Collected test results:
http://trac.bitstructures.com/browser/collected/trunk/html-test-cases/getting-tabindex-results.html?format=raw
Please let me know if you see any shortcomings in the test file or results.
Simon Bates
Adaptive Technology Resource Centre
University of Toronto
More information about the fluid-work
mailing list