JSFiddle - React, Tailwind, and code Playground

HTML

<p id="text">Click on one of these words...</p>

JavaScript

jQuery.fn.getTextNodes = function(){
        return this.not('script').contents().map(function(){
            var n = this.nodeType;
            return n === 3 ? this : n === 1 ? jQuery(this).getTextNodes().get() : [];
        });
    };
    
    jQuery('#text').getTextNodes().replaceWith(function(a,b,c){
        return jQuery(this.data.replace(/\S+/g, '<span>$&</span>')).filter('span').click(function(){
            alert('You just clicked on the word: ' + jQuery.text([this]));
        }).end();
    });