I have a div structure like following:
<div id="image0" style="margin-bottom:10px; "></div>
<div id="image1" style="margin-bottom:10px; "></div>
<div id="image2" style="margin-bottom:10px; "></div>
<div id="image3" style="margin-bottom:10px; "></div>
<div id="image4" style="margin-bottom:10px; "></div>
My jQuery code is like follows:
var res = question.text.split(imgQues);
if (question.image != '') {
for (var i = 0; i < res[0]; i++) {
jQuery('#image' + "" + i).html(question.image);
}
} else {
jQuery('#image' + "" + i).html('');
}
In my case if the res[0] is "5" code will loop to display 5 image and if res[0] value is "1" then its 1 image.
With my above code, it displays 5 images at the beginning but for next time it is still displaying 5 image not 1.
#image##every time.elsewill have undefinedivariable