I've got a small problem I'm struggling to solve. Let's say I've got an unordered list, like:
<ul>
<li> //first
<div id="div1> text </div>
</li>
<li> //second
<div id="div2> text </div>
</li>
<li> //third
<div id="div3> text </div>
</li>
&l开发者_高级运维t;/ul>
Is there an easy approach to change the order of this list? So, let's say, the third one would be displayed in the middle? The problem is I've got a lot of stuff under each
Thanks regards
You can do it by using jQueryUI. there's a very nice example here
As long as you know the positions you want to go in and move around you can. Here's an example:
In this case remove the :eq(2)
(third, 0 based) element, then insert it after the first.
$(document).ready(function(){
$("ul li:eq(2)").remove().insertAfter($("ul li:eq(0)"));
});
<ul>
<li>
<div id="div1"> first </div>
</li>
<li>
<div id="div2"> second </div>
</li>
<li>
<div id="div3"> third </div>
</li>
</ul>
There are a few other options as well, but the answer is yes you can do this.
The TinySort plugin should sort you out [TinySort]
精彩评论