0

I would like to rearrange the order of my divs.

This is my structure here:

  <div class="span8 inner-left" style="clear:both;">
    <div class="span3" style="text-align:right;"></div>
  </div>
  <div id="moreread" class="span4 inner-left"></div>

This is what I would like my outcome to be:

   <div class="span8 inner-left" style="clear:both;">
     <div class="span3" style="text-align:right;"></div>
     <div id="moreread" class="span4 inner-left"></div>
  </div>

This does not work:

$(this).find('#moreread').after(".span3");
j08691
  • 204,283
  • 31
  • 260
  • 272
user992731
  • 3,400
  • 9
  • 53
  • 83
  • 2
    Probably duplicate with http://stackoverflow.com/questions/1279957/how-to-move-an-element-into-another-element – Felix Oct 04 '12 at 22:09
  • http://stackoverflow.com/questions/4793604/how-to-do-insert-after-in-javascript-without-using-a-library – john-jones Oct 08 '14 at 11:10

3 Answers3

7

You can use appendTo method:

$('#moreread').appendTo('.span8');

Please note that your markup is invalid, you should close your div tags.

Ram
  • 143,282
  • 16
  • 168
  • 197
2

You want to either .insertAfter('.span3'), or .appendTo('.span8')

The former will always put it directly after .span3, whereas the latter will always make it the last child of .span8 - in this case the two being equivalent.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
1

HTML:

<div class="span8 inner-left" style="clear:both;">
    A
    <div class="span3" style="text-align:right;">B</div>
</div>
<div id="moreread" class="span4 inner-left">C</div>

jQuery:

$('#moreread').insertAfter('.span3');

Fiddle: http://jsfiddle.net/gromer/WD976/1/

Gromer
  • 9,861
  • 4
  • 34
  • 55