使用jQuery更改顺序div [英] change order divs with jQuery
本文介绍了使用jQuery更改顺序div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div class="test one">aaa</div>
<div class="test two">bbb</div>
<div class="test three">ccc</div>
有可能使用jQuery更改顺序吗?我想收到:
Is possible change order this divs with jQuery? I would like receive:
<div class="test two">bbb</div>
<div class="test three">ccc</div>
<div class="test one">aaa</div>
我只能使用jQuery
i can use only jQuery
我会做
推荐答案
听起来像是要移动最后一个div后的第一个div。
Sounds like you want to move the first div after the last.
$。fn.insertAfter
在参数后插入匹配的元素:
$.fn.insertAfter
inserts the matched elements after the parameter:
$(".test.one").insertAfter(".test.three");
编辑:如果你想要一个更通用的解决方案来添加第一个到最后,而不诉诸显式类: p>
If you want a more general solution of adding the first to last, without resorting to the explicit classes:
var tests = $('.test');
tests.first().insertAfter(tests.last());
这篇关于使用jQuery更改顺序div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文