By the time your code reaches the success, counter may have changed. And, your code won’t work.
That’s just one of the problems with using "array-like" ids.
Consider changing to…
- var newRow = $("<tr>").data("counter",counter);
Then whenever you need the right counter you can code
- var counter = $(this).closest("tr").data("counter");
JΛ̊KE