JSFiddle - React, Tailwind, and code Playground

HTML

<div>div 1</div>
<div id="hi">
    <span style="border:1px solid red;">This span should stay</span>
    <br />
    this should be removed
</div>
<div>div 3</div>

JavaScript

$(document).ready(function(){
$('body').children().not($('span').parents()).empty();
    
    
    
        $('#hi').contents().filter(function(){
       return this.localName !== 'span'
    }).remove();
});