Hello!
I was doing almost the same task recently.
There are various approaches to implement that.
First way is simple: we swap elements in DOM (HTML-structure) and those elements will swap visually as well.
Second way is to add special CSS rule for each element (display: flex), and manage orders by ourselves from JS.
Second approach is a bit more complicated, but it is more productive when we swap not just boxes, but big HTML sub structures, for example big tables.
Regards, Aram.