JSFiddle - React, Tailwind, and code Playground

HTML

<div id="foo">
    <img src="../img/logo.png" /> <img src="../img/logo.png" /> <img src="../img/logo.png" />&nbsp; 
</div>

JavaScript

var nodes = $("#foo").contents().filter(function() {
        return this.nodeType == 3 && /^(\s|&nbsp;)*$/.test(this.nodeValue);
    }).remove();
    
    console.log($("#foo").html());