Reputation: 134
I am creating an order form for work where you can add and remove rows with javascript. The issue I am having is after the most recent row has been removed I cannot add a new row.
I have a variable called rid
which increments each time a row is added. I need to check the row to be deleted's id against the rid
, if they are the same then it needs to lower the rid by one. I assume the issue is that the attribute and the variable are different types of string. The new rows are added using $('#tr'+rid).after()
$('div.remove').live("click", function(){
id = $(this).attr('id').replace(/r/, '');
if(id === rid){
rid = rid-1;
alert(rid);
}
$('#tr'+id).remove();
});
Upvotes: 1
Views: 127
Reputation: 11598
you should cast $(this).attr('id').replace(/r/, '')
to an int value:
var id = parseInt($(this).attr('id').replace(/r/, ''), 10);
that should work
Upvotes: 1