I am trying to dynamically display some data in an array that is returned from an ajax request. I know i have successfully retrieved the array from the server. My problem appears to be displaying the array on screen. I think I am making a mistake with designating the id of an element using a variable, and then trying to select for that ID with jquery. I have tried all sorts of combinations (playing with the single and double quotations ) as suggested by similar posts but none of them seem to work. Please can someone advise?
my code:
success: function(data){
$.each(data, function(i, element){
// display 'filename' and corresponding 'title'.
var id_name = element['filename'];
mainDiv.append('<div class="wrapper_div" id='+id_name+'></div>');
$('#' + id_name).append('<input type="checkbox" name="checkvalue[]" class="check_box" disabled="disabled" value='+element['filename']+'>');
$('#' + id_name).append('<div>' + element['filename'] + '</div>');
$('#' + id_name).append('<div>' + element['title'] + '</div>');
});
}
I know my data is there as the following code works. The items are displayed. But i really need the above code:
mainDiv.append('<input type="checkbox" name="checkvalue[]" class="check_box" disabled="disabled" value='+element['filename']+' >');
mainDiv.append('<div>' + element['filename'] + '</div>');
mainDiv.append('<div>' + element['title'] + '</div>');
id='+id_name+'
should beid="'+id_name+'"
, Your ID isn't being created as you expect it to be