JSFiddle - React, Tailwind, and code Playground
HTML
<button id="showAlerts">Show Alerts</button>
<div class="keepMe"> keep this div </div>
<div>
<ul>
<li>Item 1</li>
<li>item 2</li>
<li>
<div style="position:absolute; top:100px; right: 100px; height:50px; width: 50px; background-color: aqua;"> </div>
</li>
</ul>
</div>
<div class="keepMe"> keep this div as well </div>
JavaScript
var containerMarkup = $('body').children().not('.keepMe, #showAlerts').remove();