jQuery,将内部元素移动到第一个位置? [英] jquery, move an inner element to the first position?

查看:1638
本文介绍了jQuery,将内部元素移动到第一个位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说您有一个物品清单:

Lets say you have a list of items:

<ul id="ImportantNumbers">
   <li id="one"></li>
   <li id="two"></li>
   <li id="topNumber"></li>
   <li id="four"></li>
</ul>

这些列表项每五秒钟重新排序一次.

Every five seconds these list items get reordered.

使用 jquery 是在重新排序期间将#topNumber保留在列表顶部的最佳方法.

Using jquery whats the best way to keep #topNumber, at the top of the list during the reordering.

推荐答案

您可以使用 .prependTo() 重新排序后立即显示,如下所示:

You can use .prependTo() immediately after the re-order, like this:

$("#topNumber").prependTo("#ImportantNumbers");

您可以看到它在这里工作,它所做的就是将元素插入并作为元素插入. <ul>上的第一个孩子,有效地将其移动到顶部.

You can see it working here, all it's doing is taking the element and inserting it as the first child on the <ul>, effectively moving it to the top.

或者,在排序时,根据排序方式,使用 :not() 将其排除在外有效,例如:

Alternatively when you sort, use :not() to exclude it depending on how the sorting works, for example:

$("#ImportantNumbers li:not(#topNumber)").randomize();

这篇关于jQuery,将内部元素移动到第一个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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