使用jQuery更改顺序div [英] change order divs with jQuery

查看:923
本文介绍了使用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

http://jsfiddle.net/cmVyM/

我会做

推荐答案

听起来像是要移动最后一个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");

http:// jsfiddle.net/rP8EQ/

编辑:如果你想要一个更通用的解决方案来添加第一个到最后,而不诉诸显式类: 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆