JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<p>Some text</p>
<p>Some more text</p>
<button id="orphan">Click</button>
CSS
span.txt{
color:red;
}
JavaScript
$(function(){
$('button#orphan').click(function(){
var pNodeSplitText = [], orphanedNodes = [], pNodes = $('p');
pNodes.each(function(i){
pNodeSplitText = pNodes.eq(i).text().split(' ');
var newText = '<span class="txt">' + pNodeSplitText.join('</span> <span class="txt">') + '</span>';
$(pNodes[i]).html(newText);
console.log(newText);
});
});
});