Home › Forums › JavaScript › Why this function doesn’t work in ‘for loop’ ? [jquery] › Re: Why this function doesn’t work in ‘for loop’ ? [jquery]
March 10, 2013 at 9:01 am
#127653
Participant
if you watch your code after focusing on the first input the field that appears is the fifth one.thats because of the k var at the time of the code being executed.
i came up with this which works
for(var i=2; i<=5; i++ ){
$(‘#row’+i).hide();
}
$(‘input’).focus(function(){
var num = $(this).attr(‘id’).match(/d+$/)[0];
$(‘#row’+(+num+1)).show();
});