I'm working on a personal project, and had a question regarding jQuery and using it to loop through a JSON array.
I have the following JSON array:
var thumbDir = [
'"https://www.location.com/1.jpg"',
'"https://www.location.com/2.jpg"',
'"https://www.location.com/3.jpg"'
];
This array will have the locations for the thumbnail images for the homepage. I want to loop through them with jQuery and appendTo the following:
<div id="thumbContainer"></div>
I thought I had it figured out, with the following code, but it's not working, and I'm not sure where I'm going wrong.
$(document).ready(function(){
$.each(thumbDir, function(index, value){
$("#thumbContainer").appendTo('<img src=' + value + ' height="120" width="172">');
});
I'm pretty new to this, and it's my first project, so I'm just learning as I go. Any help would be appreciated!
appendTodoes. You wantappend$('element').appendTo('target')will append 'element' to 'target'. Since you want to add imgs to the div, you need to use$('target').append('element')