JSFiddle - React, Tailwind, and code Playground

HTML

<p>text.. <span>hi</span><a>bye</a> more text..</p>

JavaScript

(function(){
    var p = document.querySelector("p");
    var ln = p.childNodes.length;
    while (ln--){
        if(p.childNodes[ln].nodeType !== 3) { // not a text node   
            p.removeChild(p.childNodes[ln]);
        }
    }    
})();