JSFiddle - React, Tailwind, and code Playground

by btevfik

HTML

Test
<br>
Test
    <button>Click to hide</button>
    <div>TEXT
    <span>SPAN</span>
        <a href="">LINK</a>
</div>

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);
    }   
}
$('button').click(function(){
    $('body').removeText();
});