javascript - Add new form row before table and have "enter" go between rows -


i trying figure out how script add row before first table row, allow "enter" key cycle between cells. here have far, adds row after each row

var i=$('table tr').length+1; $(".addmore").on('click',function(){     addnewrow(); });  $(document).on('keypress', ".addnewrow", function(e){     var keycode = e.which ? e.which : e.keycode;     if(keycode == 9 ) addnewrow(); });  var addnewrow = function(id){     html = '<tr id="tr_'+i+'">';     html += '<td><input class="case" id="caseno_'+i+'" type="checkbox"/></td>';     html += '<td class="prod_c"><input type="text" data-type="product" name="data[product]['+i+'][product_id]" id="product_'+i+'" class="form-control autocomplete_txt" autocomplete="off">';     html +='</td>';     html += '<td><input type="checkbox" name="data[invoicedetail]['+i+'][added]" id="added_1'+i+'" class="form-control autocomplete_txt" autocomplete="off"></td>';     html += '</select></td>';     html += '</tr>';     if( typeof id !== "undefined"){         $('#tr_'+id).after(html);     }else{         $('table').append(html);     }      console.log(id);      $('#caseno_'+i).focus();      i++; 

instead of "append", use "prepend" solve issue

$('table').prepend(html); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -