focus on next tabindex of HTML element onEnter keypress by JQuery

I found a couple of minor jQuery issues. Fixed here: JSFiddle.

This line:

$('*').attr('tabindex', tabindex).focus();

can be written like this:

$('[tabindex=' + tabindex + ']').focus();

and this:

$('#Msg').text($(this).id + " tabindex: " + tabindex 
           + " next element: " + $('*').attr('tabindex').id);

is not calling the id attribute the jQuery way (you are using JavaScript syntax, but the result of $(this) is a jQuery object. So… $(this).id becomes $(this).attr('id').

The form still has a submission problem, that I didn’t dig too far into, but it changes focus and fills out the ‘#Msg’ element now.

Leave a Comment