[jQuery] Tabindex not working in Firefox on load of page

[jQuery] Tabindex not working in Firefox on load of page


I've written some code to be able to set the tabindex automatically in
our pages.
It looks like this:
$(document).ready(function() {
var el = $(".fieldsetDiv");
if (el.children().length == 0) {
el.remove();
}
//setting tabindex automatically
var totalDivs = 4;
var divNumber = 1;
$('form').each(function() {
$('.fieldsetDiv').each(function() {
var fieldNumber = 0;
$(':input', this).not('input[type=hidden]').each
(function() {
var $input = $(this);
if (fieldNumber == 0) { $input.attr("tabIndex",
divNumber); }
else { $input.attr("tabIndex", divNumber +
(fieldNumber * totalDivs)); }
fieldNumber++;
});
divNumber++;
});
});
});
It works as expected in IE, Safari, and Chrome but not in Firefox. In
Firefox when I load the page the focus is on the field with tabIndex =
1, but if I push on "tab" the focus does not go to the next field in
the taborder. The focus goes instead to the next field that does not
have a taborder specified.
If I manually put the focus on the first field of the form all works
well.
Did someone else experienced something like this in Firefox?