0

Im trying to display the images in an array onto the page but having difficulties

heres the js

     var movieArray = [
      { title: "The Artist", picture: "http://cmclove.org/img/sw_off_off.png" },
      { title: "A Better Life", picture: "http://cmclove.org/img/sw_off_off.png" },
      { title: "Abduction", picture: "http://cmclove.org/img/sw_off_off.png" },
      { title: "African Cats", picture: "http://cmclove.org/img/sw_off_off.png" },
      { title: "Angel Crest", picture: "http://cmclove.org/img/sw_off_off.png" },
      { title: "Arthur", picture: "http://cmclove.org/img/sw_off_off.png" },
      { title: "Anonymous", picture: "http://cmclove.org/img/sw_off_off.png" },
      { title: "A Dangerous Method", picture: "http://cmclove.org/img/sw_off_off.png" },
      ];

      for (var p in movieArray) {
      console.log(p+ ':' +movieArray[p].title+ '|' +movieArray[p].picture);
      } 

heres a link to the fiddle

http://jsfiddle.net/d0okie0612/YTKHh/

1
  • Your question and your fiddle don't have any logic to actually try to display the images in HTML, so I am not sure what you are asking. Commented Mar 26, 2013 at 18:32

1 Answer 1

4

You are not inserting anything into the page.

A solution would be:

for (var p = 0; p < movieArray.length; p++) {
    $('body').append('<img src="'+movieArray[p].picture+'" title="'+movieArray[p].title+'">');
}

Demo: http://jsfiddle.net/YTKHh/2/

Sign up to request clarification or add additional context in comments.

5 Comments

thats working! But is it possible to control each image by adding its own individual class and styles and stuff?
Yes, you can add the class, styles etc. to the initial array and use those inside the loop above as class and style attributes.
@user1502223 certainly it is. It depends on what you want.
i need the class names of each image to be different though....so first image will have class="1" second image will have class='2' etc...how would i do that?
That would be $('body').append('<img src="'+movieArray[p].picture+'" title="'+movieArray[p].title+'" class="'+(p+1)+'">');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.