JSFiddle - React, Tailwind, and code Playground
HTML
<div id="echo"></div>
JavaScript
var myString = "<div class='test'>My test</div><div class='anotherTest'> the other test</div>";
$("#echo").append(myString);
$("#echo").append("<br><br>now we are switching<br><br>");
var res = myString.split("</div>");
res[0] +="</div>";
res[1] +="</div>";
var switchedString=res[1]+res[0]
$("#echo").append(switchedString);
alert(switchedString);