JSFiddle - React, Tailwind, and code Playground

HTML

<div id="cont" class="container">
    <div class="no">1</div>
    <div class="no">2</div>
    <div class="no">3</div>
    <div class="blank">blank</div>
    <div class="no">4</div>
    <div class="no">5</div>
    <div class="no">6</div>
    <div class="no">7</div>
    <div class="no">8</div>
</div>

JavaScript

function swap(idx1, idx2) {
    var container = document.getElementById('cont');
    // ditch text nodes and the like
    var children = Array.prototype.filter.call(
        container.childNodes,
        function(node) {
            return node.nodeType === 1;
        }
    );
    // get references to the relevant children
    var el1 = children[idx1];
    var el2 = children[idx2];
    var el2next = children[idx2 + 1];
    
    // put the second element before the first
    container.insertBefore(el2, el1);
    // now put the first element where the second used to be
    if (el2next) container.insertBefore(el1, el2next);
    else container.appendChild(el1);
}

swap(0, 7);