2010-08-17 82 views
22

比方說你有一個項目清單:jquery,將內部元素移動到第一個位置?

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

每五秒鐘,這些列表項目將重新排序。

使用jquery什麼是最好的方式來保持#topNumber,在重新排序的列表頂部。

回答

48

您可以將重新排序後立即使用.prependTo(),像這樣:

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

You can see it working here,所有它做的是元素和插入它作爲第一個小孩的<ul>,有效地將它移到最佳。

或者當你排序,使用:not()排除它取決於如何排序的作品,例如:

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

非常感謝...它幫助了很多..... – 2016-01-07 13:37:51

相關問題