JSFiddle - React, Tailwind, and code Playground

by jfriend00

HTML

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

JavaScript

$("#foo").contents().filter(function() {
    if (this.nodeType == 3) {
        return(this.nodeValue.replace(/\s|&nbsp;/g, "") == "");
    }
    return(false);
}).remove();


alert("'" + document.getElementById("foo").innerHTML + "'");