loriensleafs
loriensleafs

Reputation: 2255

prepending images in specific order

I know this isn't the best way to do this, but unfortunately due to a deadline this is what it is. I have three images I'm loading and then prepending into a div, I'd like them to be prepended in a specific order. Right now this is what I have but I'm unsure how to prepend in the order. I don't want to use jquery load either. The images are listed in the order I'd like them to be in, I was thinking just writing it so one function doesn't start until the next is finished? But I wasn't sure how to do that either. Thanks for any help on this.

$("#pt_figures").click(function() {
$("<img>", { src: "http://www.klossal.com/figures_doc.png" }).prependTo("#images"); 
$("<img>", { src: "http://www.klossal.com/figure_front.png" }).prependTo("#images"); 
$("<img>", { src: "http://www.klossal.com/figure_back.png" }).prependTo("#images");
});

Upvotes: 0

Views: 59

Answers (1)

ahren
ahren

Reputation: 16959

The answer to your question is simple.

Use .append() not .prepend()

$("#pt_figures").click(function() {
  $("<img>", { src: "http://www.klossal.com/figures_doc.png" }).appendTo("#images"); 
  $("<img>", { src: "http://www.klossal.com/figure_front.png" }).appendTo("#images"); 
  $("<img>", { src: "http://www.klossal.com/figure_back.png" }).appendTo("#images");
});

People tend to overlook simple things when on tight deadlines - easy mistake to make.

Upvotes: 1

Related Questions