I want to add images to list from array using jQuery
index.html:
and jQuery:
(function ($) {
firstName = "";
secondName = "";
fillList("fistImagesList");
fillList("secondImagesList");
fillList("thirdImagesList");
fillList("fourthImagesList");
function fillList(name) {
for (var i = 0; i < 4; i++) {
var randomNumber = Math.floor(Math.random() * imgArray.length);
$("#" + name).append(
'
');
}
}
var imgArray = new Array();
imgArray[0] = new Image();
imgArray[0].src = "images/earth.jpg";
imgArray[0].name = "earth";
imgArray[1] = new Image();
imgArray[1].src = "images/mars.jpg";
imgArray[1].name = "mars";
imgArray[2] = new Image();
imgArray[2].src = "images/saturn.jpg";
imgArray[2].name = "saturn";
imgArray[3] = new Image();
imgArray[3].src = "images/jupiter.png";
imgArray[3].name = "jupiter";
})(jQuery);
I googled it and saw many posts about append() and appendTo() on stackoverflow.com and on other sites, but nothing happens when browser compiles my files.
maybe I have used bad jquery selector? $("#"+name). but when I using $("table.center>tbody>tr>td>ul#"+name) or $("table.center>tr>td>ul#"+name) nothing happens too.