Remove div and append after another div
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");
You can use appendTo
method:
$('#moreread').appendTo('.span8');
Please note that your markup is invalid, you should close your div tags.
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.
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/
链接地址: http://www.djcxy.com/p/42548.html下一篇: 除去另一个div后的div并追加