(1) Please don't use names of collections for private vars so var images = new Array(); better var arArrayOfImagesObjects=new Array(); images is al pre-dfined collection: document.images see http://msdn.microsoft.com/en-us/library/ms537461.aspx (2) To set scr: valueof .src is not same like pure string preload image var imgObjekt1=new Image(); // height and width if you want imgObjekt1.src='whatYouWant.jpg'; // maybe with path vImg = document.createElement("IMG"); // check pionter ! if(vImg!=null) { // append into object (into child of body) // append into collection images automatically // check pointer of appended object, use e.g. var imgAppendedImgObject if(imgAppendedImgObject!=null) {imgAppendedImgObject.src=imgObjekt1.src; // will be (now) rendered in body // don't use setAttribute("src", "images/" + image); } } (3) FIRST optimize your code during edit and THEN check errors at run time. to createElement and appendChild check always pointers != null if you use a collection like images check too declare vars inside of function --> local vars declare vars inside of for{} --> declare 1 time outside of for and use inside declare constants like "image1.jpg" outside of function --> use global code e.g. at begin of js-file (easy find and edit in js-file).