Reputation: 13166
I have a table with some rows and inputs inside them. I want add a new row with its field whenever user press + key inside text box. I could do it, but the problem I have is that this function runs just for the first time. If I press + key on the second field, nothing won't happen.
$(document).ready(function(){
$(".data").bind('keyup',function(e){
if(e.which == 107){
var id = $(this).attr('id');
var content = $('#'+id).val();
var newContent = content.replace('+','');
$('#'+id).val(newContent);
var current_rows = ($('#myTable tr').length);
current_rows = parseInt(current_rows);
var newId = current_rows + 1;
var newRow = '<td><input type="text" class="data" id="'+newId+'" /></td>';
$('#myTable tr:last').after(newRow);
$('#'+newId).focus();
}
});
$('#1').focus();
});
What I have to do ?
Upvotes: 1
Views: 94
Reputation: 11088
Try using live instead of bind. But look in documentation I think live is obsolete now.
Upvotes: 2