JSFiddle - React, Tailwind, and code Playground
HTML
<div id="first">first</div>
<div id="last">last</div>
CSS
span {color: red;}
JavaScript
function swap(a, b, direction) {
a[direction](b);
}
var firstElem = $('#first'),
secondElem = $('#last');
swap(firstElem, secondElem, 'before');