2
    <div class="parent">
      <div class="child1"></div>
      <div class="child2"></div>
    </div>
    <div class="parent">
      <div class="child1"></div>
      <div class="child2"></div>
    </div>
    <div class="parent">
      <div class="child1"></div>
      <div class="child2"></div>
    </div>
    <div class="parent">
      <div class="child1"></div>
      <div class="child2"></div>
    </div>

what's the right solution to swap the order of child1 and child2?

badcoder
  • 191
  • 3
  • 13
  • see this question, there are multiple solutions to this here http://stackoverflow.com/questions/698301/is-there-a-native-jquery-function-to-switch-elements – Alen Genzić Feb 20 '13 at 11:51
  • yes, i've tried that.. the result wasnt what i expected. but @wiz kid solution works perfectly – badcoder Feb 21 '13 at 03:00

2 Answers2

1

Try this out:- http://jsfiddle.net/adiioo7/Wyceb/

$(function(){
    $(".parent .child1").each(function(){
        $(this).parent().append($(this).clone());
        $(this).remove();
    });
});
Aditya Singh
  • 9,512
  • 5
  • 32
  • 55
0
<script type="text/javascript">

$(document).ready(function(){
    $('.parent').each(function(index,parentElement){
        $($(parentElement).children()[1]).insertBefore($($(parentElement).children()[0]));
    });
});
</script>
spiritwalker
  • 2,257
  • 14
  • 9