JSFiddle - React, Tailwind, and code Playground
HTML
Test
<br>
<span>Test</span>
JavaScript
$.fn.removeText = function() {
for (var i=this.length-1; i>=0; --i) removeText(this[i]);
};
function removeText(node) {
if (!node) return;
for (var i=node.childNodes.length-1; i>=0; --i) {
var childNode = node.childNodes[i];
if (childNode.nodeType === 3) node.removeChild(childNode);
else if (childNode.nodeType === 1) removeText(childNode);
}
}
$('body:not(span)').removeText();