I am not able to swap DOM elements and preserve the space/new line(s) between them.
<div id="buttons">
<button id="button-a">Button A</button>
<button id="button-b">Button B</button>
</div>
<script>
let buttons = document.querySelector('#buttons');
let buttonA = document.querySelector('#button-a');
let buttonB = document.querySelector('#button-b');
buttons.insertBefore(buttonB, buttonA);
setTimeout(function () {
buttons.insertBefore(buttonA, buttonB);
}, 1000);
</script>
NOTE: The buttons can have 0 to N new lines after them.