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");
2

3 Answers 3

7

You can use appendTo method:

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

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

1
  • oops, that works but it adds it before '.span3' I need to add it after
    – user992731
    Oct 4, 2012 at 22:13
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.

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/

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.