JSFiddle - React, Tailwind, and code Playground
by lollero
HTML
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
JavaScript
/**
* @param subjectIndex {int} Index of the item to be moved
* @param objectIndex {int} Index of the item to move subject after
* @param siblings {jQuery} List of sibling elements to act upon
*/
var swapElements = function(siblings, subjectIndex, objectIndex) {
// Get subject jQuery
var subject = $(siblings.get(subjectIndex));
// Get object element
var object = siblings.get(objectIndex);
// Insert subject after object
subject.insertAfter(object);
}
$(function() {
swapElements( $('li'), 0, 2 );
});