开发者

jquery, move an inner element to the first position?

Lets say yo开发者_如何学Gou 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.

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


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

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

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.

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜