Here is the jsfiddle of the code below to show a real example.
images = ["image1/url", "image2/url"] // define image source urls
$(document).ready(function(){ // wait until the document is ready
for(var i = 0; i < images.length; i++) // loop over all images
$('#option'+(i+1)).attr('src', images[i]); // set the src attribute, note the '#'
});
A couple of your mistakes:
- JQuery's
$('#id')
look-up requires the hashtag (#) for ids. - Your
filltopfoto()
function is never called (Try doingalert('hello!')
inside the function). - Your
$('options'+i)
givesoptions0
andoptions
1 -- you needoptions1
andoptions2
- Not sure why you create a
new Image
just to store asrc
variable. You can remove this code.