JSFiddle - React, Tailwind, and code Playground
by Paulpro
HTML
<div>
Test
<p> Hi</p>
<span class="bold">Yo!</span>
Yeah...
</div>
One more text node
CSS
.bold{
font-weight: 900;
}
JavaScript
// Wrap all text nodes in span tags with the class textNode
(function findTextNodes(current, callback) {
for(var i = current.childNodes.length; i--;){
var child = current.childNodes[i];
if(3 === child.nodeType)
callback(child);
findTextNodes(child, callback);
}
})(document.body, function(textNode){
$(textNode).replaceWith('<span class="textNode">' + textNode.nodeValue + '</span>');
});
// DO something on hover on those span tags
$('.textNode').hover(function(){
// Do whatever you want here
$(this).css('color', '#F00');
},function(){
// And here
$(this).css('color', '#000');
});