I want to assign unique id into HTML DIV dynamically created by jquery Ajax.
$.ajax({
type: 'xxx',
data: 'xxx',
url: 'xxx',
success: function(data) {
var repeatID =1;
$.each(data.data, function(i, v){
repeatID++;
//alert(repeatID);
$("#divId").append('<div class="single" id="my_test_' + repeatID + '">'
+'<div class="any_name"> '+ v.Name +' </div></div>');
});
error:...
});
I need to assign a unique id into class 'single'. Inside the each loop, repeatID is increasing outside append (like if I uncomment alert and there are 3 arrays returned by server then it will give alert message for three times.). But inside append it is not increasing. All the values remain the initially assigined value, 1. So, for the three DIV I got id 'my_test_1'.
I am expecting to get 'my_test_1', 'my_test_2', 'my_test_3' if there are 3 arrays. Where I am doing the wrong?
Any solution please?