JSFiddle - React, Tailwind, and code Playground

by Irvin Dominin

HTML

<h2 class="x1">1</h2>


<h2 class="x2">2</h2>


<h2 class="x3">3</h2>


<h2 class="x4">4</h2>


<h2 class="x5">5</h2>

JavaScript

jQuery.fn.swapWith = function (to) {
    return this.each(function () {
        var copy_to = $(to).clone(true);
        var copy_from = $(this).clone(true);
        $(to).replaceWith(copy_from);
        $(this).replaceWith(copy_to);
    });
};

$(document).ready(function () {
    $('.x5').swapWith('.x2');
});