2

I have a small problem, I have some static content inside a div and I need to add some extra content to it, prependTo works good, but the new content comes after the exisiting one. appendTo comes before the exisiting content, but each new appended content comes before the previous append.

Hard to explain, so I added a little example here: http://jsfiddle.net/9j958/

The foo# order is wrong, as you can see. Any way around this?

marcgg
  • 65,020
  • 52
  • 178
  • 231
WraithLux
  • 699
  • 4
  • 15
  • 22

2 Answers2

7

Reverse the elements before the each call.

$($('tr').get().reverse()).each(
    ...
);
hleinone
  • 4,470
  • 4
  • 35
  • 49
0

I'd have two suggestions.

The easier would be to add a empty div to the beginning of your fieldset and append your new elements to that instead of the fieldset directly: http://jsfiddle.net/9j958/9/

Or if for some reason you can't or don't want to change your HTML, then you could keep a reference to the last element you added and append the next element with insertAfter: http://jsfiddle.net/9j958/10/

RoToRa
  • 37,635
  • 12
  • 69
  • 105