Need to change li position by clicking to move up or to move down.
<div>
<ul>
<li>Item1 <a class="moveUp">Move Up</a> <a class="moveDown">Move Down</a></li>
<li>Item2 <a class="moveUp">Move Up</a> <a class="moveDown">Move Down</a></li>
<li>Item3 <a class="moveUp">Move Up</a> <a class="moveDown">Move Down</a></li>
<li>Item4 <a class="moveUp">Move Up</a> <a class="moveDown">Move Down</a></li>
<li>Item5 <a class="moveUp">Move Up</a> <a class="moveDown">Move Down</a></li>
</ul>
</div>
So what should happen here, for example, if we click Move up on Item2, the Item 2 will move up before Item 1.
I tryed to do like this, but it doesn’t work:
$(".moveUp").click(function () {
var thisLine = $(this).parent();
var prevLine = thisLine.prev();
prevLine.insertAfter(thisLine);
});
Hope some one can help me…
This should work and will also not move the element outside of the UL when you try and move it up at the top or down at the bottom:
Working Example: http://jsfiddle.net/BDecp/
Also, your code should be wrapped with this: