javascript - Why does keyup not work -


i'm trying input text fields focus next in line when keyup.

jquery code:

for (var counter = 0; counter < 4; counter++) {     $("<input>", {         "class":"anbox",         size: 1,         maxlength: 1     }).appendto('#answerline_' + counter); }; $(".anbox").keyup(function () {     if (this.value.length == this.maxlength) {       $(this).next('.anbox').focus();     } }); 

here a: jsfiddle

your usage of .next() incorrect. .next() function looks next sibling of element(s) in current set, optionally checking next sibling matches selector provided.

your <input> elements in different <span> elements, though, aren't siblings, , therefore can't matched using .next().

what you'll need go current <input> ($(this)), parent (.parent()), next <span> element (.next() or .next('span')), find .anbox element inside of (.find('.anbox')), focus (.focus()). looks this:

$(this).parent().next().find('.anbox').focus(); 

take @ updated jsfiddle demo.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -