I wanted to ask that is there a way by which I can append a div and an image inside it using javascript?
So basiclly, images are stored in an array. displayAllImages function() appends the images to the div #images but I want that function should append a div and within the new div there should be the image may be as a background or an image contained in a div. This should repeat for all images as in 3 images should be display as 3 divs containing 3 different images/elements of the array. Try to stick to array implementation only. Thanks!
Jsfiddle : http://jsfiddle.net/1qk3voxq/
var gallery= new Array();
gallery[0]="http://s6.tinypic.com/1zd1a47_th.jpg";
gallery[1]="http://s6.tinypic.com/2ngh9ty_th.jpg";
gallery[2]="http://s6.tinypic.com/29zy5qf_th.jpg";
var x= $("#images");
function displayAllImages() {
var i = 0,
len = gallery.length;
for (; i < gallery.length; i++) {
x.append("<img class='roll' src='" + gallery[i] + "'>");
}
};
$(function() {
displayAllImages();
});
#container {
width:600px;
height:600px;
background-color:#000;
}
.roll {
margin:4px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="container">
<div id=images></div>
</div>