I have an array of images and then I iterate through each using $.each but I can’t get the images to show on the page, it ends up with nothing getting showed.
<ul id="imagesList">
<li>No images found</li>
</ul>
$(function(){
//load image array
var images = {'image1':'assets/img/linkedin_30px.png','image2':'assets/img/twitter_30px.png'};
$.each(images, function(){
$('#imagesList').appendTo('<li>' + this + '</li>');
});
});
You are using
appendToinstead ofappend. Useappend:Or, if you insist on using
appendTo:If you want to show a loader while the image is loading, use this:
Here’s the fiddle: http://jsfiddle.net/fyar1u7a/1/