HTML:
<ul id="Items-container"> <li>1111</li> <li>2222</li> <li>3333</li> <li>4444</li> <li>5555</li> </ul>
jQuery snippet:
var swapElements = function(siblings, subjectIndex, objectIndex) { var subject = $(siblings.get(subjectIndex)); var object = siblings.get(objectIndex); subject.insertBefore(object); } $(function() { swapElements($('ul#Items-container > li'), 4, 0); // swap 1st with fifth // you can run multiple functions here like : swapElements($('div#otherContainer > p'), 2, 10); // swap 3rd with 11th });