How to reorder list items using jQuery?
7 answers
html :
<ul id="list">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
you can use after/ beforeor appendTo/ prependToto manage lists and other nodes DOM:
var $list = $('#list'),
$items = $list.children(),
$firstItem = $items.first();
//remove first item from DOM
$firstItem.detach();
//set first item after second
$items.eq(1).after($firstItem);
And after that you will have a list like this:
<ul id="list">
<li>2</li>
<li>1</li>
<li>3</li>
</ul>
0